cancel
Showing results forย 
Showย ย onlyย  | Search instead forย 
Did you mean:ย 
cnpitroda
Level 5

reading XML Values

Hi,

Can we read XML files through inbuilt functions in IS. I am using install script projects. Currently i am reading XML as a text file line by line. And then i am removing the <> tags.

Please help me.

Thanks in advance,

Chandrakant
Labels (1)
0 Kudos
(1) Reply
TheTraveler
Level 8

Hello,

Here is something you can try. The code below will allow you to read and modify a XML encoded file. Have fun... ๐Ÿ™‚

///////////////////////////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////////////////////////
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=MySQLServer;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=MyUserName;Password=MyPassword
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";

///////////////////////////////////////////////////////////////////////////
// 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;
//elseif strNamedItem = "ProductVersion" then
// oNode.attributes.getNamedItem("value").value = IFX_PRODUCT_VERSION;
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;
0 Kudos