Page 2 of 2 <12
Topic Options
#136427 - 2005-04-26 07:35 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
The second post in this thread explains it. post #2

This format is standard and needs support. Given our setup, we have no facility to write or read that format.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136428 - 2005-04-26 07:44 PM Re: RFC: XML UDF's
Shawn Administrator Offline
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
#136429 - 2005-04-26 07:48 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Nope, we already have a formatXML function to format via XSL. What I'm saying is, try to create that XML from the current UDF's we have. It's not possible, b/c we have no way to reference the first <id> tag from the second, third or fourth.

Edited by jtokach (2005-04-26 07:49 PM)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136430 - 2005-04-26 07:53 PM Re: RFC: XML UDF's
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
If its not possible, then why worry about it ? ;0)
Top
#136431 - 2005-04-26 07:54 PM Re: RFC: XML UDF's
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
I get your point, but that shoudnt be done with an Attribute like this <id number=1> FE to identify it like I posted above?.
Code:
  
<korg>
<users>
<id n=1>1</id>
<id n=2>2</id>
<id n=3>3</id>
<id n=4>4</id>
<id n=5>5</id>
</users>
</korg>





BTW have you seen such format used that much?


Edited by Jose (2005-04-26 07:58 PM)
_________________________
Life is fine.

Top
#136432 - 2005-04-26 08:19 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, that format is quite standard. I've seen it everywhere. In fact, it seems to be pretty dominant. There doesn't need to attributes is what my point is and many existing XML's may not have them so we need to address it. Example 1 at DevGuru

Example 2 (XML to SQL - This is my end goal)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136433 - 2005-04-27 01:39 AM Re: RFC: XML UDF's
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
I see Jim, you are right about its importance but I am of the thought that there is plenty to do with what is done by now, sure we will get on with it. Dont you forget there is a community behind us ready to bring a solution after a particular need .
_________________________
Life is fine.

Top
#136434 - 2005-04-27 04:34 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, I'd love to start using these now, but I think once we get into it, the specifications will all change which will force you to go back to all of your old scripts and change them as well...
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136435 - 2005-04-30 03:10 AM Re: RFC: XML UDF's
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Well I guess there is gonna have to be some more fridge for them .
_________________________
Life is fine.

Top
#136436 - 2005-05-06 10:14 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, you win. I started looking into this, and let me tell you what a massive pain in the ass it is. I'm thinking that the attributes are going to be the way to go. We'll just need to claim "limited" XML support.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136437 - 2005-05-10 08:37 PM Re: RFC: XML UDF's
jtokach Offline
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
#136438 - 2005-05-12 06:28 AM Re: RFC: XML UDF's
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Intresting concept man!.

Jim I have tryed your code but I get an error here in XMLFormatOutput($objXMLDOM) at this point.
Code:
  
$strXSL = " chr(34) + "UTF-8" + chr(34) + "?>" + @CRLF


Replaced with this and worked out.
Code:
  
$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>"



Check it Jim please.
_________________________
Life is fine.

Top
#136439 - 2005-05-12 04:45 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, this crappy board upgrade keeps dropping XML tags... I'll update the previous code and if there are no further items to work on, I think we're ready to package these up for the UDF forum.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136440 - 2005-05-12 04:51 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Regarding the missing code, the trick is to:
1. make the orignal post
2. notice missing XML/HTML tags
3. edit the post, you'll see that the code is actually there
4. save the post again and voila, it magically appears

This is a bug, which is currently working to our advantage. One of the MODS should report to Henri and/or Infopop.

Anyway, the code should work now.
_________________________
-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 Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
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 Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
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
#136443 - 2005-06-10 08:08 PM Re: RFC: XML UDF's
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
This is interesting. I can't wait to get a chance to play with it.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#136444 - 2006-02-27 09:17 AM Re: RFC: XML UDF's
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
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
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org