Jump to content
eltorro

XML DOM wrapper (COM)

Recommended Posts

cartman380

I'm sure you get this all the time but I just wanted to say these functions are amazing, and I love how easy it makes xml parsing. Thanks for your great work :)

Share this post


Link to post
Share on other sites
NDTC

Hi,

It's probably working find, but i don't understand everything... :)

But I'm very interesting for a project that must used custom XML file.

Can someone give use a little exemple for every Function of XMLDOMWrapper, with discriptions...

Thank you by advance,

Thomas.

Share this post


Link to post
Share on other sites
weaponx

This should get you started.

@eltorro - There are empty lines left over after calling _XMLDeleteNode, can you take a look at that?

;XML Function Examples - by WeaponX

#include "_XMLDomWrapper.au3"

$TempXML = @ScriptDir & "\Nodes.xml"
;---------------------------------------
;_XMLCreateFile
;---------------------------------------
ConsoleWrite("+_XMLCreateFile" & @CRLF)
_XMLCreateFile($TempXML, "Root", true)
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Failed to create file" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
    Case 3
        ConsoleWrite("File creation failed MSXML error" & @CRLF)
    Case 4
        ConsoleWrite("File exists" & @CRLF)
EndSwitch

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLFileOpen
;---------------------------------------
ConsoleWrite("+_XMLFileOpen" & @CRLF)
_XMLFileOpen($TempXML)
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Parse Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
EndSwitch

ConsoleWrite(@CRLF)

;---------------------------------------
;_XMLCreateRootChild
;---------------------------------------
ConsoleWrite("+_XMLCreateRootChild - Create child nodes below root with values" & @CRLF)
_XMLCreateRootChild("Folder", "Windows")
_XMLCreateRootChild("Folder", "Program Files")
_XMLCreateRootChild("Folder", "Documents and Settings")

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLUpdateField
;---------------------------------------
ConsoleWrite("+_XMLUpdateField - Update node value by index" & @CRLF)
_XMLUpdateField ("//Folder[3]", "Profiles")
ConsoleWrite(@CRLF)

;---------------------------------------
;_XMLGetValue / _XMLGetChildText (same result)
;---------------------------------------
ConsoleWrite("+_XMLGetValue - Retrieve value of child node by index" & @CRLF)
$Array = _XMLGetValue("//Folder[1]")
For $X = 1 to $Array[0]
    ConsoleWrite("["&$X&"]: " & $Array[$X] & @CRLF)
Next

$Array = _XMLGetValue("//Folder[2]")
For $X = 1 to $Array[0]
    ConsoleWrite("["&$X&"]: " & $Array[$X] & @CRLF)
Next

$Array = _XMLGetValue("//Folder[3]")
For $X = 1 to $Array[0]
    ConsoleWrite("["&$X&"]: " & $Array[$X] & @CRLF)
Next

ConsoleWrite(@CRLF)

ConsoleWrite("+_XMLGetValue - Retrieve all values matching XPATH" & @CRLF)
$Array = _XMLGetValue("//Folder")
For $X = 1 to $Array[0]
    ConsoleWrite("["&$X&"]: " & $Array[$X] & @CRLF)
Next

ConsoleWrite(@CRLF)

;---------------------------------------
;_XMLDeleteNode
;---------------------------------------
ConsoleWrite("+_XMLDeleteNode - Delete single child node by index" & @CRLF)
_XMLDeleteNode("//Folder[1]")
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Deletion Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
EndSwitch

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

ConsoleWrite("+_XMLDeleteNode - Delete all child nodes with the same name" & @CRLF)
_XMLDeleteNode("//Folder")
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Deletion Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
EndSwitch

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLCreateRootNodeWAttr
;---------------------------------------
ConsoleWrite("+_XMLCreateRootNodeWAttr - Create root nodes with attributes" & @CRLF)

Dim $Keys[1]
Dim $Values[1]

$Keys[0] = "Name"

$Values[0] = "Windows"
_XMLCreateRootNodeWAttr("Folder", $Keys, $Values)

$Values[0] = "Program Files"
_XMLCreateRootNodeWAttr("Folder", $Keys, $Values)

$Values[0] = "Documents and Settings"
_XMLCreateRootNodeWAttr("Folder", $Keys, $Values)

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLCreateChildWAttr
;---------------------------------------
ConsoleWrite("+_XMLCreateChildWAttr- Create subnode with attributes below a root node (by attribute)" & @CRLF)

Dim $Keys[2] = ["Name", "Size"]
Dim $Values[2]

$Values[0] = "explorer.exe"
$Values[1] = "1033728"
_XMLCreateChildWAttr("//Folder[@Name='Windows']", "File", $Keys, $Values)

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLCreateChildNode
;---------------------------------------
ConsoleWrite("+_XMLCreateChildNode- Create subnode below a root node (by index)" & @CRLF)
_XMLCreateChildNode("//Folder[3]", "File")

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLSetAttrib
;---------------------------------------
ConsoleWrite("+_XMLSetAttrib- Add attribute to subnode" & @CRLF)

;Nodes can be accessed by attribute or by index, the following point to the same node
;Attributes that don't exist will be created
_XMLSetAttrib ("//Folder[3]/File", "Name", "SomeFile.exe" )
_XMLSetAttrib ("//Folder[@Name='Documents and Settings']/File", "Size", "2048" )

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

;---------------------------------------
;_XMLDeleteNode
;---------------------------------------
ConsoleWrite("+_XMLDeleteNode - Delete Folder node by attribute" & @CRLF)
_XMLDeleteNode("//Folder[@Name='Program Files']")

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

ConsoleWrite("+_XMLDeleteNode - Delete ALL File nodes with size less than 5000000" & @CRLF)
_XMLDeleteNode("//Folder/File[@Size<5000000]")

;Output
ConsoleWrite(FileRead($TempXML) & @CRLF)

Console output:

+_XMLCreateFile
 No Error
 <?xml version="1.0"?>
 <Root/>
 
 +_XMLFileOpen
 No Error
 
 +_XMLCreateRootChild - Create child nodes below root with values
 _XMLCreateRootChild:Folder
 _XMLCreateRootChild:Folder
 _XMLCreateRootChild:Folder
 <?xml version="1.0"?>
 <Root>
 <Folder>Windows</Folder>
 <Folder>Program Files</Folder>
 <Folder>Documents and Settings</Folder>
 </Root>
 
 +_XMLUpdateField - Update node value by index
 
 +_XMLGetValue - Retrieve value of child node by index
 [1]: Windows
 [1]: Program Files
 [1]: Profiles
 
 +_XMLGetValue - Retrieve all values matching XPATH
 [1]: Windows
 [2]: Program Files
 [3]: Profiles
 
 +_XMLDeleteNode - Delete single child node by index
 Delete node Folder
 No Error
 <?xml version="1.0"?>
 <Root>
 
 <Folder>Program Files</Folder>
 <Folder>Profiles</Folder>
 </Root>
 
 +_XMLDeleteNode - Delete all child nodes with the same name
 Delete node Folder
 Delete node Folder
 No Error
 <?xml version="1.0"?>
 <Root>
 
 
 
 </Root>
 
 +_XMLCreateRootNodeWAttr - Create root nodes with attributes
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows"/>
 <Folder Name="Program Files"/>
 <Folder Name="Documents and Settings"/>
 </Root>
 
 +_XMLCreateChildWAttr- Create subnode with attributes below a root node (by attribute)
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows">
 <File Name="explorer.exe" Size="1033728"/>
 </Folder>
 <Folder Name="Program Files"/>
 <Folder Name="Documents and Settings"/>
 </Root>
 
 +_XMLCreateChildNode- Create subnode below a root node (by index)
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows">
 <File Name="explorer.exe" Size="1033728"/>
 </Folder>
 <Folder Name="Program Files"/>
 <Folder Name="Documents and Settings">
 <File/>
 </Folder>
 </Root>
 
 +_XMLSetAttrib- Add attribute to subnode
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows">
 <File Name="explorer.exe" Size="1033728"/>
 </Folder>
 <Folder Name="Program Files"/>
 <Folder Name="Documents and Settings">
 <File Name="SomeFile.exe" Size="2048"/>
 </Folder>
 </Root>
 
 +_XMLDeleteNode - Delete Folder node by attribute
 Delete node Folder
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows">
 <File Name="explorer.exe" Size="1033728"/>
 </Folder>
 
 <Folder Name="Documents and Settings">
 <File Name="SomeFile.exe" Size="2048"/>
 </Folder>
 </Root>
 
 +_XMLDeleteNode - Delete ALL File nodes with size less than 5000000
 Delete node File
 Delete node File
 <?xml version="1.0"?>
 <Root>
 
 
 
 <Folder Name="Windows">
 
 </Folder>
 
 <Folder Name="Documents and Settings">
 
 </Folder>
 </Root>
Edited by weaponx

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

I'm currently experimenting with your great code.

I'm switching it to MustDecleareVars

Line 1400 must be --> $bSuccess = False

Line 1329 should be --> Local $nodepath, $ns, $objParent

Mega

Edit: An a question : how to create this _XMLCreateFile($xml_filename, "xs:schema", True)

with a : or a blank???

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
dgriffio

hello,

it works great with a basis xml file, but i cant get it to work with what i think is a complicated one.

the xml looks as follows:

<p2v uninstallAgentOnSuccess="0" version="3.2" xmlns=""
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" xsi:type="P2VJob">

<jobState errorCode="0" id="23" startTime="2008-Jun-26 13:36:00" state="succeeded" stopTime="2008-Jun-26 13:57:48" totalPercentComplete="100" type="import">
</jobState>
</p2v>

i cant get the "state" out.

i tried that using:

#include <_XMLMdiDOM.au3>
#include <Array.au3>

Local $sFile = "test.xml"
If FileExists($sFile) Then
    $ret = _XMLFileOpen($sFile)
    If $ret = 0 Then Exit

    $state = _XMLGetValue("p2v/jobState/state")

    MsgBox(4096, "test", $state[1])
Else
    MsgBox(4096, "Error", _XMLError())
EndIf

but since its a strange structure i cant get the state out this way.

anyone have a hint for me?

Share this post


Link to post
Share on other sites
dgriffio

I found out its the xsi:type="P2VJob" giving the trouble. without it it works... anyone knows what this does and why it gives the trouble?

i really need to read the state with xsi:type="P2VJob" present...

i also changed my code:

#include <_XMLMdiDOM.au3>
#include <Array.au3>

Local $sFile = "note.xml"
If FileExists($sFile) Then
    $ret = _XMLFileOpen($sFile)
    If $ret = 0 Then Exit

    $state = _XMLGetAttrib("p2v/jobState", "state")

    MsgBox(4096, "test", $state)
Else
    MsgBox(4096, "Error", _XMLError())
EndIf

Share this post


Link to post
Share on other sites
weaponx

This works for me:

#include "_XMLDomWrapper.au3"
#include <Array.au3>

Local $sFile = "test.xml"
If FileExists($sFile) Then
    $ret = _XMLFileOpen($sFile)
    If $ret = 0 Then Exit

    $state = _XMLGetAttrib("//p2v/jobState", "state")

    MsgBox(4096, "test", $state)
Else
    MsgBox(4096, "Error", _XMLError())
EndIf

Share this post


Link to post
Share on other sites
DrJeseuss

I'm trying to deal with an XML file that is used to store data for a flash gauge. The flash will read the XML to obtain the values needed to display a needle position. When the flash is running it opens the XML for values, updates the needle position, then checks the XML again and so on. In autoit, I'm writing the XML to file, then using _FileWriteToLine I am updating only the necessary line to update the needle position. The rest stays the same. The problem is speed. By the time the file is opened, read to array, updated and rewritten, and closed, the flash file has tried to open it and been denied. This causes a delay before it will retry.

So, I'm wondering if the XML wrapper would be potentially faster at getting the file updated to prevent these file in use issues. If so, (I'm not too good with the XML stuff yet) how would I use this wrapper to modify a few values in the file? Below is the XML. In particular, I'm needing to change the values Start='110' and Span='0'. There are several instances of the rotate line, each being for a different gauge in the cluster, but I'm not sure how to identify, then change them.

CODE
<rotate x='240' y='160' start='110' span='0' step='1' shake_frequency='95' shake_span='10' shadow_alpha='30' shadow_x_offset='2' shadow_y_offset='2' >

I assume there's a way to go to a line by some internal reference (i.e. line 17) and change certain values (attribs ?) on that line.

CODE
<gauge>

<!-- small gauge -->

<circle x='240' y='160' radius='48' fill_color='88ff66' fill_alpha='80' line_thickness='8' line_alpha='30' />

<circle x='240' y='160' radius='45' start='37' end='170' fill_color='000000' fill_alpha='75' />

<circle x='240' y='160' radius='42' fill_color='88ff66' fill_alpha='90' />

<circle x='240' y='160' radius='20' fill_color='000000' fill_alpha='25' />

<text x='256' y='131' width='100' size='11' color='000000' alpha='75' align='left'>H</text>

<text x='241' y='182' width='100' size='11' color='000000' alpha='75' align='left'>C</text>

<!-- line 10 RadialTicks( 240, 160, 37, 8, 40, 168, 5, 4, "333333" ) -->

<line x1= "247.692732560257" y1= "196.191461227151" x2="249.356026086799" y2="204.016642033021" thickness= "4" color="333333" />

<line x1= "265.702359706983" y1= "186.61557261253" x2="271.259626670655" y2="192.370291015239" thickness= "4" color="333333" />

<line x1= "275.900941872212" y1= "168.951110137188" x2="283.66330768242" y2="170.886485301985" thickness= "4" color="333333" />

<line x1= "275.189091102921" y1= "148.566371208127" x2="282.797543233282" y2="146.094235253127" thickness= "4" color="333333" />

<line x1= "263.783141558402" y1= "131.656355604598" x2="268.925442435894" y2="125.528000059646" thickness= "4" color="333333" />

<rotate x='240' y='160' start='110' span='0' step='1' shake_frequency='95' shake_span='10' shadow_alpha='30' shadow_x_offset='2' shadow_y_offset='2' >

<rect x='238' y='130' width='4' height='50' fill_color='ff4400' fill_alpha='90' line_alpha='0' />

</rotate>

<!-- flashing light -->

<circle x='270' y='145' radius='3' fill_color='440000' fill_alpha='80' line_thickness='1' line_alpha='10' />

<rotate x='270' y='300' start='0' span='360000' step='120' shake_frequency='0' shake_span='0' shadow_alpha='0'>

<circle x='270' y='145' radius='3' fill_color='FF5500' fill_alpha='100' line_thickness='0' line_alpha='10' />

</rotate>

<!-- large gauge -->

<circle x='145' y='130' radius='110' fill_color='555555' fill_alpha='100' line_thickness='6' line_color='333333' line_alpha='90' />

<circle x='145' y='130' radius='100' start='240' end='480' fill_color='99bbff' fill_alpha='90' line_thickness='4' line_alpha='20' />

<circle x='145' y='130' radius='94' start='50' end='115' fill_color='FF4400' fill_alpha='100' />

<circle x='145' y='130' radius='80' start='240' end='480' fill_color='99bbff' fill_alpha='80' />

<circle x='145' y='130' radius='40' fill_color='333333' fill_alpha='100' line_alpha='0' />

<circle x='145' y='130' radius='90' start='130' end='230' fill_color='333333' fill_alpha='100' line_alpha='0' />

<!-- Line 30 RadialTicks( 145, 130, 80, 15, 250, 387, 6, 8, "000000" ) -->

<line x1= "181.319239979164" y1= "58.7194780649306" x2="188.129097475257" y2="45.3543802021051" thickness= "8" color="000000" />

<line x1= "144.441499176163" y1= "50.0019495435684" x2="144.336780271694" y2="35.0023150829875" thickness= "8" color="000000" />

<line x1= "107.689068772809" y1= "59.2335219827933" x2="100.69326916771" y2="45.964807354567" thickness= "8" color="000000" />

<line x1= "79.3080632693037" y1= "84.3429145852454" x2="66.9908251322982" y2="75.7822110699789" thickness= "8" color="000000" />

<line x1= "65.6663070093528" y1= "119.696352273795" x2="50.7912395736064" y2="117.764418325131" thickness= "8" color="000000" />

<line x1= "69.8245903371273" y1= "157.361611466053" x2="55.7292010253387" y2="162.491913615938" thickness= "8" color="000000" />

<!-- line 31 RadialTicks( 145, 130, 80, 15, 263, 400, 6, 4, "000000" ) -->

<line x1= "196.423008774923" y1= "68.7164445504818" x2="206.064822920221" y2="57.2257779036971" thickness= "4" color="000000" />

<line x1= "162.451459311723" y1= "51.9266590449002" x2="165.723607932672" y2="37.287907615819" thickness= "4" color="000000" />

<line x1= "124.564339365137" y1= "52.6541289116432" x2="120.7326529961" y2="38.1517780825763" thickness= "4" color="000000" />

<line x1= "91.2623528541609" y1= "70.7356322970599" x2="81.186544014316" y2="59.6235633527587" thickness= "4" color="000000" />

<line x1= "70.0174408406487" y1= "102.114236214255" x2="55.9582109982704" y2="96.8856555044274" thickness= "4" color="000000" />

<line x1= "65.5963078686942" y1= "139.749547472412" x2="50.7081155940744" y2="141.577587623489" thickness= "4" color="000000" />

<!-- line 32 RadialTicks( 145, 130, 80, 15, 55, 110, 3, 4, "99bbff" ) -->

<line x1= "220.175409662873" y1= "157.361611466054" x2="234.270798974661" y2="162.491913615939" thickness= "4" color="99bbff" />

<line x1= "224.315588909905" y1= "119.557904622396" x2="239.187261830512" y2="117.600011739095" thickness= "4" color="99bbff" />

<line x1= "210.532163543119" y1= "84.1138850919163" x2="222.819444207454" y2="75.5102385466506" thickness= "4" color="99bbff" />

<!-- line 33 RadialNumbers( 145, 130, 80, 0, 8, 245, 465, 9, 14, "444444" ) -->

<text x= "222.274066103125" y= "150.705523608202" width="200" size="14" color= "444444" align="left" rotation="465" >8</text>

<text x= "223.103680569595" y= "112.684830884952" width="200" size="14" color= "444444" align="left" rotation="437.5" >7</text>

<text x= "206.283555449518" y= "78.576991225077" width="200" size="14" color= "444444" align="left" rotation="410" >6</text>

<text x= "175.614674589207" y= "56.0896373990971" width="200" size="14" color= "444444" align="left" rotation="382.5" >5</text>

<text x= "138.027540580188" y= "50.3044241526603" width="200" size="14" color= "444444" align="left" rotation="355" >4</text>

<text x= "102.016031332254" y= "62.5286843349691" width="200" size="14" color= "444444" align="left" rotation="327.5" >3</text>

<text x= "75.717967697245" y= "89.9999999999999" width="200" size="14" color= "444444" align="left" rotation="300" >2</text>

<text x= "65.0761422734514" y= "126.510449010773" width="200" size="14" color= "444444" align="left" rotation="272.5" >1</text>

<text x= "72.495377037068" y= "163.809460939256" width="200" size="14" color= "444444" align="left" rotation="245" >0</text>

<rotate x='145' y='130' start='50' span='0' step='100' shake_frequency='100' shake_span='2' shadow_alpha='15'>

<rect x='143' y='40' width='4' height='100' fill_color='ffffff' fill_alpha='90' line_alpha='0' />

</rotate>

<update url='sample.xml' delay='0' delay_type='2' timeout='1' retry='5' />

<circle x='145' y='130' radius='30' fill_color='111111' fill_alpha='100' line_thickness='5' line_alpha='50' />

<text x='95' y='180' width='100' size='14' color='ffffff' alpha='70' align='center'>x1000 r/min</text>

<!-- background elements -->

<text x='-10' y='250' width='500' size='24' color='000000' alpha='20' align='left'>||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</text>

<text x='400' y='0' width='300' size='49' color='ffffff' alpha='15' align='left' rotation='90'>dashboard</text>

</gauge>

For a better understanding of the gauges, please see this link. The XML shown is for the example on the right.

Any help that can be offered would be a huge help. Thanks!

Share this post


Link to post
Share on other sites
weaponx

XML doesn't work by using line numbers as a reference. It must be treated like a database. Here I show you two ways of identifying the "rotate" node, one by attribute and one by index.

Just be careful if you are using SetAttrib matching by attribute, because the first call to it will change the query for successive calls.

#include "..\_XMLDomWrapper.au3"

Local $sFile = "test.xml"
If FileExists($sFile) Then
    $ret = _XMLFileOpen($sFile)
    If $ret = 0 Then Exit
    
    Dim $aKeys[1], $aValues[1]

    ;Get node matching multiple attributes
    _XMLGetAllAttrib ("/gauge/rotate[@x='240' and @y='160']", $aKeys, $aValues)
    For $X = 0 to Ubound($aKeys)-1
        ConsoleWrite("["&$X&"]: " & $aKeys[$X] & " = " & $aValues[$X] & @CRLF)
    Next
    
    ConsoleWrite(@CRLF)
    
    ;Get node by index
    _XMLGetAllAttrib ("/gauge/rotate[1]", $aKeys, $aValues)
    For $X = 0 to Ubound($aKeys)-1
        ConsoleWrite("["&$X&"]: " & $aKeys[$X] & " = " & $aValues[$X] & @CRLF)
    Next
    
    _XMLSetAttrib("/gauge/rotate[1]","start","NEW VALUE")
    _XMLSetAttrib("/gauge/rotate[1]","span","NEW VALUE")
Else
    MsgBox(4096, "Error", _XMLError())
EndIf

Share this post


Link to post
Share on other sites
ACalcutt

How do I write CDATA under a child node instead of under the root?

I am trying to write a kml file with this

#Include "_XMLDomWrapper.au3"
$FILE = @ScriptDir & '\KML.KML'

_XMLCreateFile($FILE, 'kml', True)
$myFile = _XMLFileOpen ($FILE)

_XMLCreateRootChild ( 'Document')
_XMLCreateChildWAttr( '/kml/Document', 'Style', 'id', 'secureStyle')
_XMLCreateChildNode ( '/kml/Document/Style', 'IconStyle')
_XMLCreateChildNode ( '/kml/Document/Style/IconStyle', 'scale', '.5') 
_XMLCreateChildNode ( '/kml/Document/Style/IconStyle', 'Icon') 
_XMLCreateChildNode ( '/kml/Document/Style/IconStyle/Icon', 'href', 'http://www.vistumbler.net/images/program-images/secure.png') 
_XMLCreateChildNode ( '/kml/Document', 'Folder') 
_XMLCreateChildNode ( '/kml/Document/Folder', 'description', 'Vistumbler - By Andrew Calcutt')
_XMLCreateChildNode ( '/kml/Document/Folder', 'name', 'Vistumbler v8.1 pre-release 1')
_XMLCreateChildNode ( '/kml/Document/Folder', 'Folder', '')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder', 'name', 'Access Points')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder', 'description', 'Access points found')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder', 'Placemark')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder/Placemark', 'name')
;_XMLCreateCDATA ( 'description', '<b>SSID: </b>dd-wrt<br /><b>Mac Address: </b>00:1A:70:75:E7:E6<br /><b>Network Type: </b>Infrastructure<br /><b>Radio Type: </b>802.11g<br /><b>Channel: </b>9<br /><b>Authentication: </b>Open<br /><b>Encryption: </b>None<br /><b>Basic Transfer Rates: </b>1 2 5.5 11<br /><b>Other Transfer Rates: </b>6 9 12 18 24 36 48 54<br /><b>First Active: </b>07-20-2008 11:28:01<br /><b>Last Updated: </b>07-20-2008 11:28:10<br /><b>Latitude: </b>N 42.0647900<br /><b>Longitude: </b>W 72.1229700<br /><b>Manufacturer: </b>Linksys<br /><b>Signal History: </b>15-0-10-0<br />')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder/Placemark', 'description', '<![CDATA[<b>SSID: </b>dd-wrt<br /><b>Mac Address: </b>00:1A:70:75:E7:E6<br /><b>Network Type: </b>Infrastructure<br /><b>Radio Type: </b>802.11g<br /><b>Channel: </b>9<br /><b>Authentication: </b>Open<br /><b>Encryption: </b>None<br /><b>Basic Transfer Rates: </b>1 2 5.5 11<br /><b>Other Transfer Rates: </b>6 9 12 18 24 36 48 54<br /><b>First Active: </b>07-20-2008 11:28:01<br /><b>Last Updated: </b>07-20-2008 11:28:10<br /><b>Latitude: </b>N 42.0647900<br /><b>Longitude: </b>W 72.1229700<br /><b>Manufacturer: </b>Linksys<br /><b>Signal History: </b>15-0-10-0<br />]]>')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder/Placemark', 'styleUrl', '#secureStyle')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder/Placemark', 'Point')
_XMLCreateChildNode ( '/kml/Document/Folder/Folder/Placemark/Point', 'coordinates', '-72.1229700,42.0647900,0')

_XMLTransform($myFile)
_XMLSaveDoc($FILE)

The output file I am trying to make should look like this.

<?xml version="1.0"?>
<kml>
<Document>
<Style id="secureStyle">
<IconStyle>
<scale>.5</scale>
<Icon>
<href>http://www.vistumbler.net/images/program-images/secure.png</href>
</Icon>
</IconStyle>
</Style>
<Folder>
<description>Vistumbler - By Andrew Calcutt</description>
<name>Vistumbler v8.1 pre-release 1</name>
<Folder>
<name>Access Points</name>
<description>Access points found</description>
<Placemark>
<name/>
<description><![CDATA[<b>SSID: </b>dd-wrt<br /><b>Mac Address: </b>00:1A:70:75:E7:E6<br /><b>Network Type: </b>Infrastructure<br /><b>Radio Type: </b>802.11g<br /><b>Channel: </b>9<br /><b>Authentication: </b>Open<br /><b>Encryption: </b>None<br /><b>Basic Transfer Rates: </b>1 2 5.5 11<br /><b>Other Transfer Rates: </b>6 9 12 18 24 36 48 54<br /><b>First Active: </b>07-20-2008 11:28:01<br /><b>Last Updated: </b>07-20-2008 11:28:10<br /><b>Latitude: </b>N 42.0647900<br /><b>Longitude: </b>W 72.1229700<br /><b>Manufacturer: </b>Linksys<br /><b>Signal History: </b>15-0-10-0<br />]]></description>
<styleUrl>#secureStyle</styleUrl>
<Point>
<coordinates>-72.1229700,42.0647900,0</coordinates>
</Point>
</Placemark>
</Folder>
</Folder>
</Document>
</kml>

kmlxml.au3

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites
DrJeseuss

WeaponX,

Let me see if I understand your second example to find a node by index. It searches the XML for any child called rotate, and assigns each an index number. So the first rotate found would be 1, the second rotate found would be 2 and so on. Then I can change attributes using the number (index) found for each occurance. So if I need to change the second rotate found, I'd use:

CODE
_XMLSetAttrib("/gauge/rotate[2]","span","NEW VALUE")

Do I understand this correctly? Thanks for the help on this!

Edited by DrJeseuss

Share this post


Link to post
Share on other sites
weaponx

By nature, each element has an index. If you have mixed node types you have more options:

<xml>
 <text>1</text>
 <text>2</text>
 <text>3</text>
 <line>1</line>
 <line>2</line>
 <line>3</line>
 <rotate>1</rotate>
 <rotate>2</rotate>
 <rotate>3</rotate>
 </xml>

You can select an absolute node like this:

//*[4]

-or-

/xml/*[4]

Giving you <line>1</line>.

Or you can use:

//line[1]

-or-

/xml/line[1]

Edited by weaponx

Share this post


Link to post
Share on other sites
PiroX

i get that error

Posted Image

to my friends it works. Does anyone know why this appears?

module not found

Edited by PiroX

Share this post


Link to post
Share on other sites
weaponx

i get that error

Posted Image

to my friends it works. Does anyone know why this appears?

module not found

That isn't enough information, I don't even know what function you're calling. Show some code.

Share this post


Link to post
Share on other sites
PiroX

That isn't enough information, I don't even know what function you're calling. Show some code.

the .xml files are totally correct

i use newest _xmldomwrapper

Func setProfilList($faction = 0, $reset = 0)
    $Ini_BG = GUICtrlRead($Settings_Battleground_Combo)
    $folder = "Profiles/" & StringLower($Ini_BG)
    $FilesArr = _FileListToArray($folder, "*", 1)
    If $reset = 0 Then GUICtrlSetData($Profiles_List, "")
    If (IsArray($FilesArr) And UBound($FilesArr) > 1) Then
        $i = 1;
        While ($i < UBound($FilesArr))
            If StringRight(StringLower($FilesArr[$i]), 3) = "xml" Then
                If _XMLFileOpen($folder & "/" & $FilesArr[$i]) = 1 Then
                    $XMLFactionArr = _XMLGetValue("/Profile/Faction")
                    If IsArray($XMLFactionArr) Then
                        If (StringLower($XMLFactionArr[1]) = "horde") Then
                            If $faction <> 1 Then GUICtrlSetData($Profiles_List, StringReplace($FilesArr[$i], ".xml", ""))
                        ElseIf (StringLower($XMLFactionArr[1]) = "alliance") Then
                            If $faction <> 2 Then GUICtrlSetData($Profiles_List, StringReplace($FilesArr[$i], ".xml", ""))
                        ElseIf (StringLower($XMLFactionArr[1]) = "both") Then
                            GUICtrlSetData($Profiles_List, StringReplace($FilesArr[$i], ".xml", ""))
                        EndIf
                    EndIf
                    
                Else
                    If @error = 1 Then MsgBox(0, "Parse Error", "FileOpen """ & $FilesArr[$i] & """ failed! Check XML Syntax.")
                EndIf
            EndIf
            $i += 1
        WEnd
    EndIf
EndFunc  ;==>setProfilList

i have those msxml in my system 32 folder

msxml.dll

msxmlr.dll

msxml2.dll

msxml2r.dll

msxml3.dll

msxml3a.dll

msxml3r.dll

msxml4.dll

msxml4r.dll

Edited by PiroX

Share this post


Link to post
Share on other sites
weaponx

Can anyone point me in the right direction on adding CDATA to somewhere other that root in my example above? ( #554094 )

It is a limitation of the _XMLCreateCDATA function. I tried briefly to fix it but I will have to look at it later.

Share this post


Link to post
Share on other sites
DrJeseuss

This is likely a simple question. After calling _XMLfileOpen it appears any calls after that (_XMLgetAttrib etc.) don't specify an XML, so must use the open XML from previous. Is there a way to have 2 XML's open or must one be used, then the other opened and used? (such as: $file1 = _XMLfileOpen($sFile1) $file2 = _XMLfileOpen($sFile2) then calling each seperately as _XMLgetAttrib($file1,"//*[4] and/or _XMLgetAttrib($file2,"//*[4]) If not, this would be a nice add.

Also, what's the proper way to stop using an XML? After using _XMLfileOpen is there a correct way to stop using a file? Nowhere do I see _XMLfileClose. Does the XML stay open until a new XML is opened or the script ends?

Lastly, I'm familiar with using _XMLgetAttrib("//Word[4]","Title") to get the value of attribute Title from the 4th Word child in the XML. I'm also familiar with using _XMLGetAttrib("//Word[@Type='Bin' and @Size=4]","Title") to get the value of attribute Title from the Word child matching Type and Size. Is there a way to get the best of both worlds? i.e. (My example doesn't work, I've tried) _XMLGetAttrib("//Word[@Type='Bin' and 4]","Title") I'm hoping to get the 4th child matching Type='Bin', not the 4th child in the XML, nor all matching Type='Bin'. Ideas?

Edited by DrJeseuss

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×