This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: XML Installscript
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
11:51 AM
XML Installscript
I am looking for a way to read a web.config that exists on the server that Is being installed on. Find a couple of specific tags and store the information then after the installation of the new files place these values into the web.config that was installed.
(22) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
12:50 PM
XML System Search and XML Changes can do this. It requires a decent understanding of XPath statements though.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
01:21 PM
The XML File Changes section is new to me. I can see how I can add information into an XML file, not for sure though how I can read information out of a XML file that is already on the target machine. I would like to be able to read in areas like appsettings and get the key and the value and display them in a dialog before the installation actually starts then based on what was read in the installer might do differant things through the dialog process. Once the installation actually starts it will probably overwrite some xml files with updated versions but needs to add back installation specific settings that were in the XML file that was already on the target machine.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
01:32 PM
Take a look at Behavior & Logic | System Search.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
02:12 PM
I do not have a system search. This is an Installscript project.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 01, 2008
02:55 PM
Oh, sorry. You'll have to write script to call the Microsoft XML Dom objects to do a query.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 02, 2008
08:42 AM
I have been searching the forums and online for installscript examples to read in information from an XML file but with no luck.
Could some one post a couple of sample scripts of an installscript function that reads an XML file like web.config and one that updates an XML file like web.config.
I mention web.config since it is one of the easiest to reference. I am looking to write an Installscript that can work with web.config files and with the METABASE.XML for IIS6+
Could some one post a couple of sample scripts of an installscript function that reads an XML file like web.config and one that updates an XML file like web.config.
I mention web.config since it is one of the easiest to reference. I am looking to write an Installscript that can work with web.config files and with the METABASE.XML for IIS6+
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 02, 2008
03:51 PM
Here is a little piece of code that I used to modify our web.config file to change the SQLConnection String. This is a good example on how to modify XML files in Install Shield Script. Keep in mind, I got a lot of how to do this from this forum...
#define ERROR_SUCCESS 0
#define ERROR_XML_FILE_CREATION "Setup could not find the web.config file %s"
#define ERROR "Error"
#define ERROR_XML_FILE_STRUCTURE "The web.config file structure is corrupted.%s"
#define ERROR_XML_FILE_LOAD "The web.config file was not loaded.%s"
prototype ModifyWebConfig(BYVAL STRING, BYREF STRING);
///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
function ModifyWebConfig(strFileName, strError)
OBJECT oDoc, oNode, oNodeList;
NUMBER i, nSize;
STRING strNamedItem;
STRING strValue;
begin
///////////////////////////////////////////////////////////////////////////
// Check to see if the file exists... //
///////////////////////////////////////////////////////////////////////////
if Is(FILE_EXISTS, strFileName) = TRUE then
//MessageBox("XML file exists",0);
else
MessageBox("XML file is missing",0);
endif;
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
nSize = 300;
i = 0;
//"Data Source="+ m_strDBDataSource +";"+
strValue = "Data Source=" + m_strDBDataSource;
strValue = strValue +";User Id=" + m_strDBUserName;
strValue = strValue +";Password=" + m_strDBPassword;
strValue = strValue +";Initial Catalog="+ m_strDBName;
strValue = strValue +";Persist Security Info=True";
if m_strADOConnectionTimeout != "" then
strValue = strValue +";Connection Timeout="+ m_strADOConnectionTimeout;
else
strValue = strValue +";Connection Timeout="+ SQL_CONNECTION_TIMEOUT;
endif;
///////////////////////////////////////////////////////////////////////////
// get values from public properties
///////////////////////////////////////////////////////////////////////////
set oDoc = CreateObject("Msxml2.DOMDocument.4.0");
if (IsObject(oDoc) = FALSE) then
MessageBox(ERROR_XML_FILE_CREATION, 0);
return -1;
endif;
oDoc.async = FALSE;
oDoc.setProperty("SelectionLanguage", "XPath");
///////////////////////////////////////////////////////////////////////////
// if success, traverse file and substitute value //
///////////////////////////////////////////////////////////////////////////
if oDoc.load(strFileName) then
///////////////////////////////////////////////////////////////////////
// get list of matching nodes //
///////////////////////////////////////////////////////////////////////
set oNodeList = oDoc.getElementsByTagName("*");
if (oNodeList.length > 0) then
for i = 0 to (oNodeList.length - 1);
set oNode = oNodeList.nextNode;
try
strNamedItem = oNode.attributes.getNamedItem("key").value;
catch
strNamedItem = "";
endcatch;
try
if strNamedItem = "SQLConnection" then
oNode.attributes.getNamedItem("value").value = strValue;
endif;
catch
endcatch;
endfor;
else
MessageBox(ERROR_XML_FILE_STRUCTURE,SEVERE);
return -1;
endif;
else
MessageBox(ERROR_XML_FILE_LOAD,SEVERE);
return -1;
endif;
oDoc.save(strFileName);
set oDoc = NOTHING;
end;
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 02, 2008
03:55 PM
Thank you very much, I have been looking through the forums and online and most of what I had found was about MSI and builds. I will start changing up they way I run searches in these forums. Thank you for letting me know that most of the information I probably seek is in the forums. 🙂
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 04, 2008
02:38 PM
I started with the script provided by The Traveler, however I was needing to edit a somewhat complicated XML file created by a different software package that included a default namespace and was failing the DTD Schema verification. I got around this by figuring out how to define the namespace(s) to search under in XPath and using an older version of DOM that didn't do the DTD verification. Here is the code with explanation if it can help anyone else avoid several days of learning about XPath and namespaces.
[CODE]prototype ModifyXmlAttribute( STRING , NUMBER , STRING , STRING , STRING , STRING );
/*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute
Description: This function changes the value of an attribute associated with
one or more elements defined by an Xpath statement. If there are
multiple elements matching the Xpath statement, this function will
offer to change the attributes of all matching elements, or abort.
Inputs: svFile = The full path to the XML file to modify.
nNamespace = 1 to use namespace in search, 0 to not use namespace.
svNamespace = Only used if nNamespace = 1. This the namespace to be used
in the Xpath search string. If not used, enter "" for value.
svXpath = The Xpath statement that defines the element(s) containing the
attribute to be modified.
svAttribute = The name of the attribute to be modified.
svValue = The value to be written to the specified attribute.
Return: 0 - The attributes of all matching elements were successfully changed.
Greater than 0 - Some or all attribute changes failed.
Example:
XML File:
Function Variables:
svFile = "Path\\to\\your\\file.xml"
nNamespace = 1
svNamespace = "xmlns:pro='http://deltabis.com/products' xmlns:itin='http://deltabis.com/itinerary'"
svXpath = "//pro:lists/pro:product[@type='tshirt']/itin:itinerary"
svAttribute = "sold"
svValue = "1000"
Result:
Before:
After:
Notes: If a default namespace is defined (xmlns=something) in the XML file, that
namespace will have to be defined or the Xpath search will not return any
elements. For more information, go to http://www.xml.com/lpt/a/979
*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute( svFile , nNamespace , svNamespace , svXpath , svAttribute , svValue )
OBJECT oDoc, oNode, oNodeList, oDocType;
STRING svMessage, svError, svLine, svLinePos;
NUMBER i, nFailed;
begin
nFailed = 0;
// Check to see if the file exists...
if Is( FILE_EXISTS , svFile ) = FALSE then
MessageBox("XML file does not exist.",0);
return 1;
endif;
//Set XML DOM Object
set oDoc = CreateObject( "Microsoft.XMLDOM" );
if ( IsObject( oDoc ) = FALSE ) then
MessageBox( "MSXML DOM-Document Connection Failed" , 0 );
return 1;
endif;
oDoc.async = FALSE;
//Set namespace and load file
oDoc.setProperty( "SelectionLanguage" , "XPath" );
oDoc.setProperty( "SelectionNamespaces" , svNamespace );
oDoc.load( svFile );
if ( oDoc.parseError.errorCode != 0 ) then
NumToStr ( svError , oDoc.parseError.errorCode );
NumToStr ( svLine , oDoc.parseError.line );
NumToStr ( svLinePos , oDoc.parseError.linepos );
MessageBox ( "The XML File did not load correctly.\n" +
"Error Code: " + svError + "\n" +
"Error Line: " + svLine + "\n" +
"Error Line Position: " + svLinePos + "\n" +
oDoc.parseError.reason , 0 );
return 1;
endif;
//Search XML File for all matching elements
set oNodeList = oDoc.selectNodes( svXpath );
//If no matching elements
if ( oNodeList.length = 0 ) then
MessageBox( "No matching elements found." , 0 );
return 1;
endif;
//If more than one matching elements
if ( oNodeList.length > 1 ) then
svMessage = "There is more than one matching element. Press YES to accept changing all nodes or NO to quit";
if ( AskYesNo ( svMessage , YES ) = 0 ) then
return 1;
endif;
endif;
//Change attribute for all matching elements
for i = 0 to ( oNodeList.length - 1 );
set oNode = oNodeList.nextNode;
try
oNode.attributes.getNamedItem( svAttribute ).value = svValue;
catch
nFailed = nFailed + 1;
endcatch;
endfor;
oDoc.save( svFile );
set oDoc = NOTHING;
set oNode = NOTHING;
set oNodeList = NOTHING;
return nFailed;
end;[/CODE]
[CODE]prototype ModifyXmlAttribute( STRING , NUMBER , STRING , STRING , STRING , STRING );
/*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute
Description: This function changes the value of an attribute associated with
one or more elements defined by an Xpath statement. If there are
multiple elements matching the Xpath statement, this function will
offer to change the attributes of all matching elements, or abort.
Inputs: svFile = The full path to the XML file to modify.
nNamespace = 1 to use namespace in search, 0 to not use namespace.
svNamespace = Only used if nNamespace = 1. This the namespace to be used
in the Xpath search string. If not used, enter "" for value.
svXpath = The Xpath statement that defines the element(s) containing the
attribute to be modified.
svAttribute = The name of the attribute to be modified.
svValue = The value to be written to the specified attribute.
Return: 0 - The attributes of all matching elements were successfully changed.
Greater than 0 - Some or all attribute changes failed.
Example:
XML File:
Function Variables:
svFile = "Path\\to\\your\\file.xml"
nNamespace = 1
svNamespace = "xmlns:pro='http://deltabis.com/products' xmlns:itin='http://deltabis.com/itinerary'"
svXpath = "//pro:lists/pro:product[@type='tshirt']/itin:itinerary"
svAttribute = "sold"
svValue = "1000"
Result:
Before:
After:
Notes: If a default namespace is defined (xmlns=something) in the XML file, that
namespace will have to be defined or the Xpath search will not return any
elements. For more information, go to http://www.xml.com/lpt/a/979
*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute( svFile , nNamespace , svNamespace , svXpath , svAttribute , svValue )
OBJECT oDoc, oNode, oNodeList, oDocType;
STRING svMessage, svError, svLine, svLinePos;
NUMBER i, nFailed;
begin
nFailed = 0;
// Check to see if the file exists...
if Is( FILE_EXISTS , svFile ) = FALSE then
MessageBox("XML file does not exist.",0);
return 1;
endif;
//Set XML DOM Object
set oDoc = CreateObject( "Microsoft.XMLDOM" );
if ( IsObject( oDoc ) = FALSE ) then
MessageBox( "MSXML DOM-Document Connection Failed" , 0 );
return 1;
endif;
oDoc.async = FALSE;
//Set namespace and load file
oDoc.setProperty( "SelectionLanguage" , "XPath" );
oDoc.setProperty( "SelectionNamespaces" , svNamespace );
oDoc.load( svFile );
if ( oDoc.parseError.errorCode != 0 ) then
NumToStr ( svError , oDoc.parseError.errorCode );
NumToStr ( svLine , oDoc.parseError.line );
NumToStr ( svLinePos , oDoc.parseError.linepos );
MessageBox ( "The XML File did not load correctly.\n" +
"Error Code: " + svError + "\n" +
"Error Line: " + svLine + "\n" +
"Error Line Position: " + svLinePos + "\n" +
oDoc.parseError.reason , 0 );
return 1;
endif;
//Search XML File for all matching elements
set oNodeList = oDoc.selectNodes( svXpath );
//If no matching elements
if ( oNodeList.length = 0 ) then
MessageBox( "No matching elements found." , 0 );
return 1;
endif;
//If more than one matching elements
if ( oNodeList.length > 1 ) then
svMessage = "There is more than one matching element. Press YES to accept changing all nodes or NO to quit";
if ( AskYesNo ( svMessage , YES ) = 0 ) then
return 1;
endif;
endif;
//Change attribute for all matching elements
for i = 0 to ( oNodeList.length - 1 );
set oNode = oNodeList.nextNode;
try
oNode.attributes.getNamedItem( svAttribute ).value = svValue;
catch
nFailed = nFailed + 1;
endcatch;
endfor;
oDoc.save( svFile );
set oDoc = NOTHING;
set oNode = NOTHING;
set oNodeList = NOTHING;
return nFailed;
end;[/CODE]
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Oct 06, 2008
11:01 AM
this posts above helped me a lot...
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jan 30, 2009
11:04 AM
While I appreciate all of the examples, this is a horrible piece of functionality in InstallShield. I don't want to have to resort to these measures to do what should be a "simple" update to an existing .xml file. I am not an XML programmer, nor do I want to be - that is why we spend thousands of dollars on a tool like InstallShield that is supposed to do these things for us. Extremely disappointed in this functionality, or lack thereof.
Tim
Tim
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 15, 2024
12:50 PM
Sharing the same feeling in 2024
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 14, 2009
04:37 PM
Where are you declaring variables such as m_strDBDataSource? I would take it we need access to variables set by the SQL dialog (i.e. IS_SQLSERVER_SERVER, IS_SQLSERVER_USERNAME, etc.)
Thanks
Thanks
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 09, 2009
10:16 AM
Hi,
If my XML file begins like this:
And I need to replace IpAdress and Port value.
What would be the value of svXpath ?
Thanks,
Bianca
If my XML file begins like this:
4
*
1935
..........
And I need to replace IpAdress and Port value.
What would be the value of svXpath ?
Thanks,
Bianca
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 09, 2009
10:37 AM
Just add your config/xml file in the XML file editor, and then you'll see those elements pop up. After you load the document, on the element work area on the right there will be a tab/section where you can replace those fields with properties from your project.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 10, 2009
02:23 AM
Hi,
The XML files I need to handle don't belong to my install package, but to an already installed application to which I need to add some elements and replace some values of current elements.
The XML Import menu in IS is not handling files from other applications right ?
Thanks for you time,
Bianca
The XML files I need to handle don't belong to my install package, but to an already installed application to which I need to add some elements and replace some values of current elements.
The XML Import menu in IS is not handling files from other applications right ?
Thanks for you time,
Bianca
cspanellis wrote:
Just add your config/xml file in the XML file editor, and then you'll see those elements pop up. After you load the document, on the element work area on the right there will be a tab/section where you can replace those fields with properties from your project.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 10, 2009
04:11 AM
I call the function like this:
And nothing is updated in the file. I don;t know if svXpath is defined correctly.
My file is :
Also I need to add new elements in the file. For this I found no solution.
Thanks,
Bianca
svFile = appapath ^ "\\conf\\$VHost.xml";
svXpath ="//Root/VHost/HostPortList/HostPort/IpAddress";
svAttribute = "*";
svValue = "${BindAddress}";
ModifyXmlAttribute( svFile , 0 , "" , svXpath , svAttribute , svValue );
And nothing is updated in the file. I don;t know if svXpath is defined correctly.
My file is :
4
*
1935
Also I need to add new elements in the file. For this I found no solution.
Thanks,
Bianca
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 10, 2009
04:25 PM
I think you can modify any file, whether it's in your project or not. You may just have to specify the proper location to match where it will be. It actually gives you an option to create the file if it doesn't exist so I'm pretty sure you can modify any file.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jun 11, 2009
02:00 AM
No you can't. I imported the XML file from it's location c:\Program Files\.... and during installation IS creates the file in my application install dir.
Bianca
Bianca
cspanellis wrote:
I think you can modify any file, whether it's in your project or not. You may just have to specify the proper location to match where it will be. It actually gives you an option to create the file if it doesn't exist so I'm pretty sure you can modify any file.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 16, 2010
05:24 PM
Unfortunately, this piece of code is not doing anything in case when a namespace defined... Any advice?
jcouvret wrote:
I started with the script provided by The Traveler, however I was needing to edit a somewhat complicated XML file created by a different software package that included a default namespace and was failing the DTD Schema verification. I got around this by figuring out how to define the namespace(s) to search under in XPath and using an older version of DOM that didn't do the DTD verification. Here is the code with explanation if it can help anyone else avoid several days of learning about XPath and namespaces.
[CODE]prototype ModifyXmlAttribute( STRING , NUMBER , STRING , STRING , STRING , STRING );
/*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute
Description: This function changes the value of an attribute associated with
one or more elements defined by an Xpath statement. If there are
multiple elements matching the Xpath statement, this function will
offer to change the attributes of all matching elements, or abort.
Inputs: svFile = The full path to the XML file to modify.
nNamespace = 1 to use namespace in search, 0 to not use namespace.
svNamespace = Only used if nNamespace = 1. This the namespace to be used
in the Xpath search string. If not used, enter "" for value.
svXpath = The Xpath statement that defines the element(s) containing the
attribute to be modified.
svAttribute = The name of the attribute to be modified.
svValue = The value to be written to the specified attribute.
Return: 0 - The attributes of all matching elements were successfully changed.
Greater than 0 - Some or all attribute changes failed.
Example:
XML File:
Function Variables:
svFile = "Path\\to\\your\\file.xml"
nNamespace = 1
svNamespace = "xmlns:pro='http://deltabis.com/products' xmlns:itin='http://deltabis.com/itinerary'"
svXpath = "//pro:lists/pro:product[@type='tshirt']/itin:itinerary"
svAttribute = "sold"
svValue = "1000"
Result:
Before:
After:
Notes: If a default namespace is defined (xmlns=something) in the XML file, that
namespace will have to be defined or the Xpath search will not return any
elements. For more information, go to http://www.xml.com/lpt/a/979
*////////////////////////////////////////////////////////////////////////////////////
function ModifyXmlAttribute( svFile , nNamespace , svNamespace , svXpath , svAttribute , svValue )
OBJECT oDoc, oNode, oNodeList, oDocType;
STRING svMessage, svError, svLine, svLinePos;
NUMBER i, nFailed;
begin
nFailed = 0;
// Check to see if the file exists...
if Is( FILE_EXISTS , svFile ) = FALSE then
MessageBox("XML file does not exist.",0);
return 1;
endif;
//Set XML DOM Object
set oDoc = CreateObject( "Microsoft.XMLDOM" );
if ( IsObject( oDoc ) = FALSE ) then
MessageBox( "MSXML DOM-Document Connection Failed" , 0 );
return 1;
endif;
oDoc.async = FALSE;
//Set namespace and load file
oDoc.setProperty( "SelectionLanguage" , "XPath" );
oDoc.setProperty( "SelectionNamespaces" , svNamespace );
oDoc.load( svFile );
if ( oDoc.parseError.errorCode != 0 ) then
NumToStr ( svError , oDoc.parseError.errorCode );
NumToStr ( svLine , oDoc.parseError.line );
NumToStr ( svLinePos , oDoc.parseError.linepos );
MessageBox ( "The XML File did not load correctly.\n" +
"Error Code: " + svError + "\n" +
"Error Line: " + svLine + "\n" +
"Error Line Position: " + svLinePos + "\n" +
oDoc.parseError.reason , 0 );
return 1;
endif;
//Search XML File for all matching elements
set oNodeList = oDoc.selectNodes( svXpath );
//If no matching elements
if ( oNodeList.length = 0 ) then
MessageBox( "No matching elements found." , 0 );
return 1;
endif;
//If more than one matching elements
if ( oNodeList.length > 1 ) then
svMessage = "There is more than one matching element. Press YES to accept changing all nodes or NO to quit";
if ( AskYesNo ( svMessage , YES ) = 0 ) then
return 1;
endif;
endif;
//Change attribute for all matching elements
for i = 0 to ( oNodeList.length - 1 );
set oNode = oNodeList.nextNode;
try
oNode.attributes.getNamedItem( svAttribute ).value = svValue;
catch
nFailed = nFailed + 1;
endcatch;
endfor;
oDoc.save( svFile );
set oDoc = NOTHING;
set oNode = NOTHING;
set oNodeList = NOTHING;
return nFailed;
end;[/CODE]
![](/skins/images/3B39CE851FDD5528C393F146EB70A2D0/responsive_peak/images/icon_anonymous_message.png)