Realized I probably shoudn't hijack Chris's thread ... in regards to XML and as an offshoot to that thread ...

What I was thinking guys, was to create a matched pair of ReadProfileString/WriteProfileString work-alikes for XML files, to "ease" the interface when one just wants to read/write things like settings, here's a quick prototype of a matched set, plus a snippet of code to demonstrate usage.


break on

$filename = "e:\test.xml"

$xml = LoadXml($filename)

$= WriteXmlValue($xml, "korg/shawn/number", 119)
$= WriteXmlValue($xml, "korg/jose/number", 1772)
$= WriteXmlValue($xml, "korg/jooel/number", 2087)

?"Value=" ReadXmlValue($xml, "korg/jose/number")

SaveXml($xml, $filename)

$xml = 0

exit 1

---
[udf]
Code:

function LoadXml($filename)

dim $, $rootNode

$loadXml = CreateObject("Microsoft.XMLDOM");

if not $loadXml
return
endif

$= $loadXml.Load($filename)

endfunction


function WriteXmlValue($xml, $path, $value)

dim $p, $rootNode, $sectionNode, $parentNode, $childNode

$sectionNode = $xml.SelectSingleNode($path);

if not $sectionNode

$parentNode = $xml

for each $node in split($path,"/")

$p = $p + $node

$sectionNode = $xml.SelectSingleNode($p)

if not $sectionNode

$sectionNode = $xml.CreateElement($node)

$parentNode = $parentNode.AppendChild($sectionNode)

else

$parentNode = $sectionNode

endif

$p = $p + "/"

next

endif

if $sectionNode
$sectionNode.Text = $value
endif

endfunction

function SaveXml($xml, $filename)

$SaveXml = $xml.Save($filename);

endfunction


function ReadXmlValue($xml, $key, optional $defaultValue)

dim $sectionNode

$sectionNode = $xml.SelectSingleNode($key);

if not $sectionNode
$ReadXmlValue = $defaultValue;
else
$ReadXmlValue = $sectionNode.FirstChild.Text;
endif

endfunction



Thoughts ?