Jump to content
Sign in to follow this  
chenxu

How to read items in this xml file?

Recommended Posts

chenxu

CODE
<?xml version="1.0" ?>

<menu>

<item name="item 1" exe="d:\test1.exe" arg="aaa, bbb"/>

<item name="item 2" exe="d:\test2.exe" arg="aaa, bbb"/>

<item name="item 3" exe="d:\test3.exe" arg="aaa, bbb"/>

<item name="item 4" exe="d:\test4.exe" arg="aaa, bbb"/>

<item name="item 5" exe="d:\test5.exe" arg="aaa, bbb"/>

</menu>

I don't kown how to get all items with _XMLDomWrapper.au3, I still can't do what I want after search the forum, help me please, give me any advice or example code

Share this post


Link to post
Share on other sites
bluelamp

Ok, I tried to read your xml with this UDF.

I think it can´t be done because this UDF

assumes that your nodes have different names.

Here is my testcode:

#include <_XMLDomWrapper.au3>
#Include <Array.au3>
Const $file = "file.xml"

If _XMLFileOpen($file,"",-1) == -1 Then
    ConsoleWrite("can´t open file!"&@CRLF)
    Exit
EndIf

$array = _XMLGetChildNodes("/menu")
_ArrayDisplay($array)
For $i=1 To $array[0]
    ConsoleWrite(_XMLGetAttrib($array[$i],"name")&@CRLF)
Next

Look at this -> #544372

Edited by bluelamp

Share this post


Link to post
Share on other sites
PsaltyDS

Ok, I tried to read your xml with this UDF.

I think it can´t be done because this UDF

assumes that your nodes have different names.

Not true. It is very common to have multiple items with the same tag ("item" in this case), and they are then addressed by 1-based instance in the path used. From the example XML file, "/menu/item[2]" would address the second instance:
#include <_XMLDOMWrapper.au3>

; Open file
$sXML = "Test_1.xml"
If _XMLFileOpen($sXML,"",-1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

; Get count of item nodes in menu
$iItems = _XMLGetNodeCount("/menu/item")
ConsoleWrite("$iItems = " & $iItems & @LF)

; List the "name" attribute of each item
For $i = 1 To $iItems
    ConsoleWrite(_XMLGetAttrib("/menu/item[" & $i & "]","name") & @CRLF)
Next

Google up the details of XML Path (or XPath) syntax for more details.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.