$filename = "config.xml"
$xml = LoadXml($filename)
$= WriteXmlValue($xml, "lib/config/HistoryAge", "500")
SaveXml($xml, $filename)
$xml = 0
$newfile = 0
Function LoadXml($filename)
Dim $, $rootNode
$loadXml = CreateObject("Microsoft.XMLDOM");
If NOT $loadXml
Return
EndIf
$= $loadXml.async="false"
if Not Exist ($filename)
$newfile = 1
Endif
$= $loadXml.Load($filename)
EndFunction
Function InsertHeader($xml)
$header= $xml.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
$= $xml.insertBefore($header,$xml.childNodes.Item(0))
EndFunction
Function SaveXml($xml, $filename)
if ($newfile = 1)
InsertHeader($xml)
Endif
$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
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 WriteXMLattrib($xml, $Path, $Attr, $Value)
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrTag = $SelectionTag.item(0)
$eu = $AttrTag.SetAttribute($Attr,$Value);
EndFunction
Function ReadXMLattrib($xml, $Path, $Attr)
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrName = $SelectionTag.item(0)
$ReadXMLattrib =$AttrName.getAttribute($Attr)
EndFunction