Ok, with apologies to Chris, borrowing his "loadxml" idea, here is a complete set of UDF's for loading/reading/writing/saving from XML files ... looks like this:
break on
$xml = LoadXml("e:\t.xml")
$= WriteXmlString($xml, "shawn/jose", 100)
$= WriteXmlString($xml, "shawn/jose/settings/form1/left", 123)
SaveXml($xml, "e:\t.xml")
$xml = 0
exit 1
[udf]
Code:
function LoadXml($filename)
dim $, $rootNode
$loadXml = CreateObject("Microsoft.XMLDOM");
if not $loadXml
return
endif
if not $loadXml.Load($filename)
$rootNode = $loadXml.createElement("root");
if $rootNode
$= $loadXml.AppendChild($rootNode);
endif
endif
endfunction
function SaveXml($xml, $filename)
$SaveXml = $xml.Save($filename);
endfunction
function WriteXmlString($xml, $path, $value)
dim $rootNode, $sectionNode;
$sectionNode = $xml.SelectSingleNode("/root/" + $path);
if not $sectionNode
$sectionNode = $xml.documentElement
for each $node in split($path,"/")
$childNode = $xml.CreateElement($node)
$sectionNode = $sectionNode.AppendChild($childNode)
next
endif
$sectionNode.Text = $value;
return
endfunction
function ReadXmlString($xml, $key, optional $defaultValue)
dim $sectionNode
$sectionNode = $xml.SelectSingleNode("/root/" + $key);
if not $sectionNode
$ReadXmlString = $defaultValue;
else
$ReadXmlString = $sectionNode.FirstChild.Text;
endif
endfunction