#136428 - 2005-04-26 07:44 PM
Re: RFC: XML UDF's
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
So based on this link, we could create a Kixtart function called FormatXML(), is that where your heading ?
-Shawn
|
Top
|
|
|
|
#136437 - 2005-05-10 08:37 PM
Re: RFC: XML UDF's
|
jtokach
Seasoned Scripter
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
Ok, pain in the ass or not, I couldn't find any way around this, so I spent some time and got it working.
Also note that I changed all of the function names so they all match up and can be sorted and searched on easier. Here's all of the latest code and an example that creates an XML file, parses it and writes some SQL based on it.
Code:
Break On $nul=SetOption("ASCII","On") $nul=SetOption("Explicit","On") $nul=SetOption("WrapAtEOL","On")
Dim $fileXMLdata Dim $xml, $
Dim $SQL,$iSQL,$uSQL,$DBServer,$DBName,$DBType,$DSN,$DBUsername,$DBPassword Dim $TableName,$PKey,$SKey,$FieldNames,$FieldData Dim $colXMLElements,$colE Dim $arySQL[0]
$fileXMLdata = "db.xml"
; Delete an existing XML file as the append functions will append to an ; existing file If Exist($fileXMLdata) Del $fileXMLdata EndIf
; Create the XML file using the new append functions $= XMLAppendElement($fileXMLdata, "Database", "") $= XMLAppendAttr($fileXMLdata, "Database", "Server", "MyServer") $= XMLAppendAttr($fileXMLdata, "Database", "Name", "MyDB") $= XMLAppendAttr($fileXMLdata, "Database", "Type", "MySQL") $= XMLAppendAttr($fileXMLdata, "Database", "Username", "root") $= XMLAppendAttr($fileXMLdata, "Database", "Password", "MyPass")
$= XMLAppendElement($fileXMLdata, "Database/Table", "") $= XMLAppendAttr($fileXMLdata, "Database/Table", "Name", "Computers") $= XMLAppendAttr($fileXMLdata, "Database/Table", "PrimaryKey", "Hostname") $= XMLAppendAttr($fileXMLdata, "Database/Table", "SecondaryKey", "")
$= XMLAppendElement($fileXMLdata, "Database/Table/Record", "") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hostname", "COMPUTER01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/LastUpdated", @Date + " " + @Time) $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareMake", "Dell Computer Corporation") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareModel", "OptiPlex GX200") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareSN", "123572256132345") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareBiosVer", "DELL - 8|Phoenix ROM BIOS PLUS Version 1.10 A03|") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareBiosDate", "02/28/01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/HardwareCPU", @CPU)
$= XMLAppendElement($fileXMLdata, "Database/Table", "") $= XMLAppendAttr($fileXMLdata, "Database/Table", "Name", "Hotfixes") $= XMLAppendAttr($fileXMLdata, "Database/Table", "PrimaryKey", "Hostname") $= XMLAppendAttr($fileXMLdata, "Database/Table", "SecondaryKey", "Hotfix")
$= XMLAppendElement($fileXMLdata, "Database/Table/Record", "") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hostname", "COMPUTER01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/LastUpdated", @Date + " " + @Time) $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hotfix", "MS04_011")
$= XMLAppendElement($fileXMLdata, "Database/Table/Record", "") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hostname", "COMPUTER01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/LastUpdated", @Date + " " + @Time) $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hotfix", "MS04_012")
$= XMLAppendElement($fileXMLdata, "Database/Table/Record", "") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hostname", "COMPUTER01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/LastUpdated", @Date + " " + @Time) $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hotfix", "MS04_013")
$= XMLAppendElement($fileXMLdata, "Database/Table/Record", "") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hostname", "COMPUTER01") $= XMLAppendElement($fileXMLdata, "Database/Table/Record/LastUpdated", @Date + " " + @Time) $= XMLAppendElement($fileXMLdata, "Database/Table/Record/Hotfix", "MS04_014")
$xml = 0
; Enumerate all of the elements in the XML file into a collection of objects $colXMLElements = XMLEnumElements($fileXMLdata,"*")
; Iterate the collection, create SQL statments with the data, add each statement ; to an array For Each $colE In $colXMLElements Select Case $colE.TagName = "Database" $DBServer = $colE.getAttribute("Server") $DBName = $colE.getAttribute("Name") $DBType = $colE.getAttribute("Type") $DBUsername = $colE.getAttribute("Username") $DBPassword = $colE.getAttribute("Password") If $DBType = "MySQL" $DSN="DRIVER={MySQL ODBC 3.51 Driver};SERVER="+$DBServer+";DATABASE="+$DBName+";UID="+$DBUsername+";PWD="+$DBPassword EndIf
Case $colE.TagName = "Table" $TableName = $colE.getAttribute("Name") $PKey = $colE.getAttribute("PrimaryKey") $SKey = $colE.getAttribute("SecondaryKey")
Case $colE.TagName = "Record" If $FieldNames <> "" ;$uSQL = "UPDATE " + $TableName + " SET " + $element + " WHERE " + $KeyName + " = '" + $KeyData + "'" $iSQL = "INSERT INTO " + $TableName + "(" + $FieldNames + ") VALUES (" + $FieldData + ")" $arySQL[ubound($arySQL)]=$iSQL Redim Preserve $arySQL[ubound($arySQL)+1] EndIf $SQL = "" $FieldNames = "" $FieldData = "" Case 1 ; Must be a record for the current table. If $FieldNames = "" $FieldNames = $colE.TagName $FieldData = "'" + $colE.Text + "'" Else $FieldNames = $FieldNames + "," + $colE.TagName $FieldData = $FieldData + ",'" + $colE.Text + "'" EndIf EndSelect Next ; Adds the remaining parsed data to the array $iSQL = "INSERT INTO " + $TableName + "(" + $FieldNames + ") VALUES (" + $FieldData + ")" $arySQL[ubound($arySQL)]=$iSQL
; Print the data to the console ? "DSN: " + $DSN ? Dim $k For Each $k In $arySQL ? "iSQL: " + $k Next
Exit 1
Function XMLAppendAttr($source, $Path, $Attr, $Value) Dim $SelectionTag,$AttrTag,$,$Write,$xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$SelectionTag = $xml.getElementsByTagName($Path) $AttrTag = $SelectionTag.item($SelectionTag.length-1) If @ERROR = "-2147352573" $ = XMLWriteValue($xml, $path, "") $SelectionTag = $xml.getElementsByTagName($Path) $AttrTag = $SelectionTag.item($SelectionTag.length-1) EndIf $write = $AttrTag.SetAttribute($Attr,$Value)
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLWriteAttr = $xml Else If Instr($source,"<")=0
; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) Else ; An XML string was passed. $XMLWriteAttr = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy EndFunction
; XMLAppendElement() - Writes a value to an XML element Function XMLAppendElement($source, $path, $value) dim $, $p, $rootNode, $sectionNode, $parentNode, $childNode, $node, $xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed ;? "filename" $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$sectionNode = $xml.SelectSingleNode($path);
if not $sectionNode ; The node does not exist $parentNode = $xml
for each $node in split($path,"/") Dim $colXMLElements $p = $p + $node
$colXMLElements = $xml.getElementsByTagName($p) If $colXMLElements.length > 1 $sectionNode = $colXMLElements.Item($colXMLElements.length-1) Else $sectionNode = $xml.SelectSingleNode($p) EndIf
if not $sectionNode $sectionNode = $xml.CreateElement($node) $parentNode = $parentNode.AppendChild($sectionNode) else $parentNode = $sectionNode endif $p = $p + "/" next Else Dim $colXMLElements Dim $aryNodes Dim $ParentNodeName ;? "Does exist, appending" ;The node does exist, get the count of each $aryNodes = split($path,"/") $Node = $aryNodes[ubound($aryNodes)] ;? "Node "$node $ParentNodeName = Join($aryNodes,"/",Ubound($aryNodes)) ;? "PN " $parentnodeName
$colXMLElements = $xml.getElementsByTagName($ParentNodeName) If $colXMLElements.length > 1 ;? "more than one" ;? "c " $colXMLElements.length ;? "item "$colXMLElements.Item($colXMLElements.length-1).TagName $ParentNode = $colXMLElements.Item($colXMLElements.length-1) ;$ParentNode = $xml.SelectSingleNode($parentnodeName) Else ;? "not more than one" ;$sectionNode = $xml.SelectSingleNode($parentnode) ;? "SN " $sectionNode.TagName $ParentNode = $xml.SelectSingleNode($parentnodeName) EndIf $sectionNode = $xml.CreateElement($node) $parentNode = $parentNode.AppendChild($sectionNode) EndIf
; wrtie val to current section If $sectionNode $sectionNode.Text = $value EndIf
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLAppendElement = $xml Else If Instr($source,"<")=0 ;? "Save" ; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) ;? "save2" Else ; An XML string was passed. $XMLAppendElement = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy
endfunction
; XMLCreateElement() - Creates an empty element pair Function XMLCreateElement($source,$path) $XMLCreateElement = XMLWriteValue($source,$path,"") EndFunction
; XMLEnumAttr() - Enums all attributes of an element Function XMLEnumAttr($source,$path) Dim $xml,$
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting *** Dim $colXMLElements,$colE $colXMLElements = $xml.getElementsByTagName($path) If $colXMLElements.item(0).Attributes.length > 0 $XMLEnumAttr = $colXMLElements.item(0).Attributes EndIf EndFunction
; XMLEnumElements() - Enums child elements of a given element Function XMLEnumElements($source,$path) Dim $xml,$
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting *** ;Select ; Case Right($path,1)= "/" ; $path = Left($path,Len($path)-1) ; ;? "path "$path ; $XMLEnumElements = $xml.getElementsByTagName($path).Item(0) ; $XMLEnumElements = $XMLEnumElements.ChildNodes ; Case 1 ; $XMLEnumElements = $xml.getElementsByTagName($path) ;EndSelect $XMLEnumElements = $xml.getElementsByTagName($path) EndFunction
;XMLFormatOutput() - Formats the output style of an XMLDOM object to the standard Function XMLFormatOutput($objXMLDOM)
;? "V" vartype($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) $XMLFormatOutput = $objXMLDOM EndFunction
;XMLLoad() - Load an existing .XML file, instantiate XMLDOM object for use ;regardless of file existance. Function XMLLoad($filename) dim $, $rootNode, $objNewPI, $strType
$XMLLoad = CreateObject("Microsoft.XMLDOM") $XMLLoad.async = False $XMLLoad.preserverwhitespace = True
if not $XMLLoad return endif
$ = $XMLLoad.Load($filename) EndFunction
; XMLReadAttr() - Read a specific attribute of an XML element Function XMLReadAttr($source, $Path, $Attr) Dim $SelectionTag,$AttrName,$,$xml ; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$SelectionTag = $xml.getElementsByTagName($Path) $AttrName = $SelectionTag.item(0) If @ERROR = "-2147352573" $XMLReadAttr = "" Exit @Error Else $XMLReadAttr =$AttrName.getAttribute($Attr) EndIf
; Begin Overloaded Var Exit Strategy ; None needed ; End Overloaded Var Exit Strategy EndFunction
;XMLReadValue() - Reads the value of an XML element Function XMLReadValue($source, $key, optional $defaultValue) Dim $sectionNode,$xml,$
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$sectionNode = $xml.SelectSingleNode($key) If not $sectionNode $XMLReadValue = $defaultValue Else $XMLReadValue = $sectionNode.FirstChild.Text EndIf EndFunction
; XMLRemoveAttr() - Deletes an XML element attribute Function XMLRemoveAttr($source, $Path, $attr, optional $id) Dim $SelectionTag,$AttrTag,$erase,$,$xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$SelectionTag = $xml.getElementsByTagName($Path) If $id="" $id=0 EndIf $AttrTag = $SelectionTag.item($id) $erase = $AttrTag.removeAttribute($attr)
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLRemoveAttr = $xml Else If Instr($source,"<")=0
; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) Else ; An XML string was passed. $XMLRemoveAttr = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy
EndFunction
; XMLRemoveElement() - Deletes an XML element (Recursively?) Function XMLRemoveElement($source,$path) Dim $SelectionTag,$AttrTag,$,$xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$SelectionTag = $xml.getElementsByTagName($path) Dim $i
For $i=0 To $SelectionTag.Length - 1 ;? "Index "$i ;? "Removing "$SelectionTag.item($i).TagName ;? "Parent " $SelectionTag.item($i).ParentNode.TagName $=$SelectionTag.item($i).ParentNode.RemoveChild($SelectionTag.item($i)) ;? @Serror Next
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLRemoveElement = $xml Else If Instr($source,"<")=0
; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) Else ; An XML string was passed. $XMLRemoveElement = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy EndFunction
;XMLSave() - Saves an XMLDOM object to a file ; Requires: XMLFormatOutput() Function XMLSave($xml, $filename) $xml = XMLFormatOutput($xml) $XMLSave = $xml.Save($filename) EndFunction
Function XMLWriteAttr($source, $Path, $Attr, $Value) Dim $SelectionTag,$AttrTag,$,$Write,$xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$SelectionTag = $xml.getElementsByTagName($Path) $AttrTag = $SelectionTag.item(0) If @ERROR = "-2147352573" $ = XMLWriteValue($xml, $path, "") $SelectionTag = $xml.getElementsByTagName($Path) $AttrTag = $SelectionTag.item(0) EndIf $write = $AttrTag.SetAttribute($Attr,$Value)
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLWriteAttr = $xml Else If Instr($source,"<")=0
; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) Else ; An XML string was passed. $XMLWriteAttr = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy EndFunction
; XMLWriteValue() - Writes a value to an XML element Function XMLWriteValue($source, $path, $value) dim $, $p, $rootNode, $sectionNode, $parentNode, $childNode, $node, $xml
; *** Begin Overloaded Var Sorting *** If VarType($source) = 9 ; An object was passed $xml = $source Else If Instr($source,"<")=0 ; A file name was passed $xml = XMLLoad($source) Else ; An XML string was passed $xml = CreateObject("Microsoft.XMLDOM") $xml.async = false $=$xml.LoadXML($source) EndIf EndIf ; *** End Overloaded Var Sorting ***
$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
; Begin Overloaded Var Exit Strategy If VarType($source) = 9 ; An object was passed. $XMLWriteValue = $xml Else If Instr($source,"<")=0
; A file name was passed, so we write it out and destory the object XMLSave($xml, $source) Else ; An XML string was passed. $XMLWriteValue = $xml
EndIf EndIf ; End Overloaded Var Exit Strategy
endfunction
; ****************************************************************************** ; XMLApplyXSL() - Applies an XSL template. (Much potential here for an expanded ; set, see http://www.devguru.com/Technologies/xslt/quickref/xslt_index.html Function XMLApplyXSL()
EndFunction
; XMLApplyXSLFilter() - Apply a filter to an XMLDOM object. (Search the db. XSL related.) Function XMLApplyXSLFilter()
EndFunction
Function XMLEnum($source) dim $nodelist,$i $NodeList = $source.getElementsByTagName("*") ;For Each $i In $NodeList ;? "Element " +$i.tagName ;? "attributes: " $i.attributes ;? "baseName: " $i.baseName ;? "childNodes: " $i.childNodes ;? "dataType: " $i.dataType ;? "definition: " $i.definition ;? "firstChild: " $i.firstChild.nodeName ;? "lastChild: " $i.lastChild.nodeName ;? "namespaceURI: " $i.namespaceURI ;? "nextSibling: " $i.nextSibling.nodeName ;? "nodeName: " $i.nodeName ;? "nodeType: " $i.nodeType ;? "nodeTypeString: " $i.nodeTypeString ;? "nodeValue: " $i.nodeValue ;? "ownerDocument: " $i.ownerDocument ;? "parentNode: " $i.parentNode.nodeName ;? "parsed: " $i.parsed ;? "prefix: " $i.prefix ;? "previousSibling: " $i.previousSibling.nodeName ;? "specified: " $i.specified ;? "tagName: " $i.tagName ;? "text: " $i.text ;? "xml: " $i.xml ;? ;Next $XMLEnum = $NodeList EndFunction
Edited by jtokach (2005-05-12 04:47 PM)
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
Top
|
|
|
|
#136441 - 2005-05-26 10:45 PM
Re: RFC: XML UDF's
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Just FYI if interested - not really of much help internally though with KiXtart.
Improve XML Processing with VTD-XML
|
Top
|
|
|
|
#136442 - 2005-06-05 12:36 AM
Re: RFC: XML UDF's
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Jim,
Just ran across this in the WMI materials. Here is an example. Shawn has a mini reader that read the output just fine. Not solid code, but example works.
SWbemObjectEx.GetText_ The GetText_ method of the SWbemObjectEx object returns an XML representation of an object or instance. The text file is formatted in the XML format specified as shown in WbemObjectTextFormatEnum.
WbemObjectTextFormatEnum
Code:
Break On Dim $SO,$Pause $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('WrapAtEOL','Off') Dim $MyBIOSInfo,$W $MyBIOSInfo = GetBIOSInfo() If Exist('C:\TEMP\TEST.XML') DEL 'C:\TEMP\TEST.XML' EndIf $W = Open(1, 'C:\TEMP\TEST.XML',5) $W = WriteLine(1,$MyBIOSInfo[0]+@CRLF) $W = Close(1) Function GetBIOSInfo() Dim $Computer, $WMIService, $BIOSItems Dim $Item, $SerialNumber, $Manufacturer, $BIOSArray[1] Dim $XMLDtd $XMLDtd = 2 $Computer = "." $WMIService = GetObject("winmgmts:\\" + $Computer + "\root\cimv2") $BIOSItems = $WMIService.ExecQuery("Select * from Win32_BIOS",,48) For Each $Item in $BIOSItems $SerialNumber = $Item.GetText_($XMLDtd) Next $BIOSArray[0]=$SerialNumber $GetBIOSInfo=$BIOSArray EndFunction
|
Top
|
|
|
|
#136444 - 2006-02-27 09:17 AM
Re: RFC: XML UDF's
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Not sure if you've seen this or not as I've not reviewed all the code you've written so far.
How to navigate XML with the XPathNavigator class by using Visual Basic http://support.microsoft.com/kb/301111/en-us
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 980 anonymous users online.
|
|
|