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
- :
- InstallAnywhere
- :
- InstallAnywhere Forum
- :
- Re: how to replace an xml attribute with a new value in installer
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 21, 2008
09:30 AM
how to replace an xml attribute with a new value in installer
thanks pv...
i have another requirement as a part of the installer...
As a part of our project .. we have a java class .. which generates like a productKey by passing some arguments..
i need to copy that key which is a string to an xml file..
i can see an action called perform xsltransform.. but dont know how to replace an atrributes value with the new one
As always .. waiting for a nice solution
i have another requirement as a part of the installer...
As a part of our project .. we have a java class .. which generates like a productKey by passing some arguments..
i need to copy that key which is a string to an xml file..
i can see an action called perform xsltransform.. but dont know how to replace an atrributes value with the new one
As always .. waiting for a nice solution
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 21, 2008
09:54 AM
Hello,
Install shield has the ability to create COM objects and use them. We use it to modify a web.config file which is XML encoded.
Install shield has the ability to create COM objects and use them. We use it to modify a web.config file which is XML encoded.
#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, BYVAL 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;
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 28, 2008
03:09 PM
You could also use a specific string (like MY_PRODUCT_KEY) inside the .xml file and use the 'Modify Text File - Single File' action to replace the content of this string with a variable containing your product key. It's simpler but it might do the job for you.
To set this up, click the 'Configure...' button near the 'Search and replace strings' in the action
If you prefer java to c you can also write a Custom Action instead of a COM object.
To set this up, click the 'Configure...' button near the 'Search and replace strings' in the action
If you prefer java to c you can also write a Custom Action instead of a COM object.
![](/skins/images/8CE4FAD0DE6F3A6F9D0567434D2D2DAE/responsive_peak/images/icon_anonymous_message.png)