Here's all of what we have so far. Some functions have been renamed from their original.
LoadXML() - Load an existing .XML file, instantiate XMLDOM object for use regardless of file existance.
SaveXML() - Saves an XMLDOM object
FormatXML() - Formats the output style of an XMLDOM object to the standard
EnumXMLElement() - Enums child elements of a given element
EnumXMLAttr() - Enums all attributes of an element
CreateXMLElement() - Creates an empty element pair
RemoveXMLElement() - Deletes an XML element (Recursively?)
WriteXMLValue() - Writes a value to an XML element
ReadXMLValue() - Reads the value of an XML element
WriteXMLAttr() - Writes an attribute to an XML element
ReadXMLAttr() - Read a specific attribute of an XML element
RemoveXMLAttr() - Deletes an XML element attribut
Secondary functions
ApplyXSL() - Applies an XSL template. (Much potential here for an expanded set, see
http://www.devguru.com/Technologies/xslt/quickref/xslt_index.html
or NTDOC's post above.
FilterXML() - Apply a filter to an XMLDOM object. (Search the db. XSL related.)
Code:
; CreateXMLElement() - Creates an empty element pair
Function CreateXMLElement()
EndFunction
; EnumXMLAttr() - Enums all attributes of an element
Function EnumXMLAttr()
EndFunction
; EnumXMLElement() - Enums child elements of a given element
Function EnumXMLElement()
EndFunction
;FormatXML() - Formats the output style of an XMLDOM object to the standard
Function FormatXML($objXMLDOM)
Dim $,$strXSL,$objXSL
;Create and Load XSL
; <?xml version="1.0" encoding="UTF-8"?>
; <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
; <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
; <xsl:template match="/ | @* | node()">
; <xsl:copy>
; <xsl:apply-templates select="@* | node()" />
; </xsl:copy>
; </xsl:template>
; </xsl:stylesheet>
$strXSL = "<?xml version=" + chr(34) + "1.0" + chr(34) + " encoding=" +
chr(34) + "UTF-8" + chr(34) + "?>" + @CRLF
$strXSL = $strXSL + "<xsl:stylesheet version=" + chr(34) + "1.0" + chr(34) +
" xmlns:xsl=" + chr(34) + "http://www.w3.org/1999/XSL/Transform" +
chr(34) + ">" + @CRLF
$strXSL = $strXSL + "<xsl:output method=" + chr(34) + "xml" + chr(34) +
" version=" + chr(34) + "1.0" + chr(34) + " encoding=" + chr(34) +
"UTF-8" + chr(34) + " indent=" + chr(34) + "yes" + chr(34) + "/>" + @CRLF
$strXSL = $strXSL + "<xsl:template match=" + chr(34) + "/ | @@* | node()" +
chr(34) + ">" + @CRLF
$strXSL = $strXSL + "<xsl:copy>"+ @CRLF
$strXSL = $strXSL + "<xsl:apply-templates select=" + chr(34) +
"@@* | node()" + chr(34) + " />"+ @CRLF
$strXSL = $strXSL + "</xsl:copy>"+ @CRLF
$strXSL = $strXSL + "</xsl:template>"+ @CRLF
$strXSL = $strXSL + "</xsl:stylesheet>"
;? "XLM Stylesheet: " + @CRLF + $strXSL
$objXSL = CreateObject("Microsoft.XMLDOM")
$objXSL.async = false
$=$objXSL.loadXML($strXSL)
;Transform file
$objXMLDOM.TransformNodeToObject ($objXSL, $objXMLDOM)
$formatXML = $objXMLDOM
EndFunction
;LoadXML() - Load an existing .XML file, instantiate XMLDOM object for use
;regardless of file existance.
Function LoadXML($filename)
dim $, $rootNode, $objNewPI, $strType
$loadXml = CreateObject("Microsoft.XMLDOM")
$loadXml.async = False
$loadXml.preserverwhitespace = True
if not $loadXml
return
endif
$ = $loadXml.Load($filename)
EndFunction
; ReadXMLAttr() - Read a specific attribute of an XML element
Function ReadXMLAttr($xml, $Path, $Attr)
Dim $SelectionTag,$AttrName
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrName = $SelectionTag.item(0)
If @Serror = "Member not found."
$ReadXMLAttr = ""
Exit @Error
Else
$ReadXMLAttr =$AttrName.getAttribute($Attr)
EndIf
EndFunction
;ReadXMLElement() - Reads the value of an XML element
Function ReadXMLValue($xml, $key, optional $defaultValue)
Dim $sectionNode
$sectionNode = $xml.SelectSingleNode($key)
If not $sectionNode
$ReadXmlValue = $defaultValue
Else
$ReadXmlValue = $sectionNode.FirstChild.Text
EndIf
EndFunction
; RemoveXMLAttr() - Deletes an XML element attribute
Function RemoveXMLAttr($xml, $Path, $attr, optional $id)
Dim $SelectionTag,$AttrTag,$erase
$SelectionTag = $xml.getElementsByTagName($Path)
If $id=""
$id=0
EndIf
$AttrTag = $SelectionTag.item($id)
$erase = $AttrTag.removeAttribute($attr)
EndFunction
; RemoveXMLElement() - Deletes an XML element (Recursively?)
Function RemoveXMLElement()
EndFunction
;SaveXML() - Saves an XMLDOM object to a file
; Requires: FormatXML()
Function SaveXML($xml, $filename)
$xml = FormatXML($xml)
$SaveXml = $xml.Save($filename)
EndFunction
; WriteXMLAttr() - Writes an attribute to an XML element
Function WriteXMLAttr($xml, $Path, $Attr, $Value)
Dim $SelectionTag,$AttrTag,$,$eu
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrTag = $SelectionTag.item(0)
If @Serror = "Member not found."
$ = WriteXmlValue($xml, $path, "")
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrTag = $SelectionTag.item(0)
EndIf
$eu = $AttrTag.SetAttribute($Attr,$Value)
EndFunction
; WriteXMLValue() - Writes a value to an XML element
Function WriteXMLValue($xml, $path, $value)
dim $p, $rootNode, $sectionNode, $parentNode, $childNode,$node
$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
; ******************************************************************************
; ApplyXSL() - Applies an XSL template. (Much potential here for an expanded
; set, see http://www.devguru.com/Technologies/xslt/quickref/xslt_index.html
Function ApplyXSL()
EndFunction
; FilterXML() - Apply a filter to an XMLDOM object. (Search the db. XSL related.)
Function FilterXML()
EndFunction