Jump to content

Recommended Posts

Posted

Delare the namespaces that are used and pass them to the open statement. Then prefix each node with the namespace.

XML namespaces give me a headache. But try this.

#Include <_XMLDomWrapper.au3>
$xmlns = 'xmlns:Settings="http://www.microsoft.com/GroupPolicy/Settings" xmlns:q3="http://www.microsoft.com/GroupPolicy/Settings/Registry"'
$xml = _XMLFileOpen (@ScriptDir & "\c.xml",$xmlns)
If @error Then Exit
$a = _XMLGetValue("/Settings:GPO/Settings:User/Settings:ExtensionData/Settings:Extension/q3:Policy/q3:Name")
ConsoleWrite(_XMLError()&@lf)
If IsArray($a) Then msgbox(0,"1",$a[1])
$a = _XMLGetValue("/Settings:GPO/Settings:User/Settings:ExtensionData/Settings:Extension/q3:Policy/q3:State")
ConsoleWrite(_XMLError()&@lf)
If IsArray($a) Then msgbox(0,"1",$a[1])
Posted

Hello,

I have beginner-problems with the _XMLDomWrapper.au3, V1.0.3.82 2007.07.09 and XMLExample.au3 from the first posting of this thread.

If I try to comile it with the 3.2.10.0, I get a lot of errors with the first lines, e.g.:

<br />

<b>Warning</b>: filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for files/public_downloads/BackUp/_xmldomwrapper_old1.au3 in <b>/var/www/web1/web/fileman/index.php</b> on line <b>424</b><br />

<br />

What should it be?

If I delete all this lines, I get the next error:

_XMLArrayAdd(): undefined function

I don't find this function, neither in _XMLDomWrapper.au3 nor in XMLExample.au3.

What do I wrong or what anything else I need too?

Many thanks in advance

skyteddy

Posted (edited)

It would help if you posted your errors from the output window in scite.

Edited by eltorro
Posted

It would help if you posted your script.

Thank you for you offer. Until now, I don't have a own script. I only uses the _XMLDomWrapper.au3 and the XMLExample.au3 from the first posting of this thread. The only chage I made was to modify the path of the include of the "_XMLDomWrapper.au3" in the XMLExample.au3. Then I try to compile the XMLExample.au3 and I got the reported errors.

Many thanks

skyteddy

Posted

It would help if you posted your errors from the output window in scite.

Error 1 with unmodified files:

D:\autoit\XML\_XMLDomWrapper.au3(1,1) : ERROR: syntax error

<

^

D:\autoit\XML\XMLExample.au3 - 1 error(s), 0 warning(s)

If I delete all the lines above

; =======================================================================

; Project Manager 3.0 Preprocessed - Date 25:04:2007 Time 14:28

; =======================================================================

The next error:

D:\autoit\XML\_XMLDomWrapper.au3(348,48) : ERROR: _XMLArrayAdd(): undefined function.

_XMLArrayAdd($arrResponse, $objNode.nodeName)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\autoit\XML\_XMLDomWrapper.au3(765,32) : ERROR: _AddFormat(): undefined function.

_AddFormat($objDoc, $objNode)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\autoit\XML\XMLExample.au3 - 2 error(s), 0 warning(s)

Thank you

skyteddy

Posted

Error 1 with unmodified files:

D:\autoit\XML\_XMLDomWrapper.au3(1,1) : ERROR: syntax error

<

^

D:\autoit\XML\XMLExample.au3 - 1 error(s), 0 warning(s)

If I delete all the lines above

; =======================================================================

; Project Manager 3.0 Preprocessed - Date 25:04:2007 Time 14:28

; =======================================================================

The next error:

D:\autoit\XML\_XMLDomWrapper.au3(348,48) : ERROR: _XMLArrayAdd(): undefined function.

_XMLArrayAdd($arrResponse, $objNode.nodeName)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\autoit\XML\_XMLDomWrapper.au3(765,32) : ERROR: _AddFormat(): undefined function.

_AddFormat($objDoc, $objNode)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\autoit\XML\XMLExample.au3 - 2 error(s), 0 warning(s)

Thank you

skyteddy

It sounds like the a bad download. I would try it again.
Posted

It sounds like the a bad download. I would try it again.

Argl :-( , this was my first idea yesterday and I tried the download 3 times with no difference. I cleared all the local caches. Today I got a _XMLDomWrapper.au3 which is much more longer and without the first 20 suspected lines. :-)

Thank you very much eltorro. Now I try to understand your example and the functions in _XMLDomWrapper.au3.

skyteddy

Posted

Is there an equivalent in _XMLDomWrapper for the VB XML function ReadNodeItemList?

This can be used to "walk" a set of identically named subnodes extracting all attributes and values, for example

<?xml version="1.0" encoding="ISO-8859-1"?>
<main>
   <data attr=1>
       <item>value</item>
       <item>value2</item>
   </data>
   <data attr=2>
       <item>value</item>
       <item>value2</item>
   </data>
</main>

If not, how would one "walk" the above using _XMLDomWrapper to extract all attributes and valuse for all elements?

Regards,

Jim

Posted

You can use the index to identify the subnode.

/main/data[1]/item[1]

#Include <_XMLDomWrapper.au3>
$xml = _XMLFileOpen (@ScriptDir & "\main.xml")
If @error Then
    ConsoleWrite(_XMLError()&@lf)
    Exit
EndIf
Walk()
Func Walk($path = ".")
    $a = _XMLGetChildNodes ($path)
    If IsArray($a) Then
        For $x = 1 To $a[0]
            ConsoleWrite($path & "/" & $a[$x] & "[" & $x & "]" & @LF)
            Dim $at[1], $av[1]
            $b = _XMLGetAllAttrib ($path & "/" & $a[$x] & "[" & $x & "]", $at, $av)
            If Not @error Then
                If IsArray($B) Then
                    For $y = 0 To UBound($at) - 1
                        ConsoleWrite(StringFormat("\tAttribute::%s=%s\n", $at[$y], $av[$y]))
                    Next
                EndIf
            EndIf
            Walk($path & "/" & $a[$x] & "[" & $x & "]")
        Next
    EndIf
EndFunc   ;==>Walk

Also, attribute values need to be quoted.

<?xml version="1.0" encoding="iso-8859-1"?>
<main>
  <data attr="1">
    <item test="one">value 
      <item>subvalue1</item>
    </item>
    <item>value2</item>
  </data>
  <data attr="2">
    <item>value</item>
    <item>value2</item>
  </data>
</main>
Posted

You can use the index to identify the subnode.

/main/data[1]/item[1]

#Include <_XMLDomWrapper.au3>
$xml = _XMLFileOpen (@ScriptDir & "\main.xml")
If @error Then
    ConsoleWrite(_XMLError()&@lf)
    Exit
EndIf
Walk()
Func Walk($path = ".")
    $a = _XMLGetChildNodes ($path)
    If IsArray($a) Then
        For $x = 1 To $a[0]
            ConsoleWrite($path & "/" & $a[$x] & "[" & $x & "]" & @LF)
            Dim $at[1], $av[1]
            $b = _XMLGetAllAttrib ($path & "/" & $a[$x] & "[" & $x & "]", $at, $av)
            If Not @error Then
                If IsArray($B) Then
                    For $y = 0 To UBound($at) - 1
                        ConsoleWrite(StringFormat("\tAttribute::%s=%s\n", $at[$y], $av[$y]))
                    Next
                EndIf
            EndIf
            Walk($path & "/" & $a[$x] & "[" & $x & "]")
        Next
    EndIf
EndFunc   ;==>Walk

Also, attribute values need to be quoted.

<?xml version="1.0" encoding="iso-8859-1"?>
<main>
  <data attr="1">
    <item test="one">value 
      <item>subvalue1</item>
    </item>
    <item>value2</item>
  </data>
  <data attr="2">
    <item>value</item>
    <item>value2</item>
  </data>
</main>
eltorro,

Thank you. Your first code snippet solved my original problem but your program example gave me enough information to solve another problem.

I apologize for my ignorance on this but I am accustomed to using the Java XML support which really simplifies this type of processing.

Rgards,

Jim

  • 2 weeks later...
Posted

Okay, I'm trying to parse an XML file but for some reason, the parser refuses to work if this line is in play:

<feed version="0.3" xmlns="http://purl.org/atom/ns">

I did some testing and from what I can tell it is because there are two 'thingies' in there, (Sorry, having a bad night). Just wondering what solution I can use to parse this example file:

<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns">
    <fullcount>2</fullcount>
</feed>

Say for example I just wanted to get the value of <fullcount> from there. I'm sure there is probably some super simple explanation!

Thanks!

Posted

Okay, I'm trying to parse an XML file but for some reason, the parser refuses to work if this line is in play:

<feed version="0.3" xmlns="http://purl.org/atom/ns">

I did some testing and from what I can tell it is because there are two 'thingies' in there, (Sorry, having a bad night). Just wondering what solution I can use to parse this example file:

<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns">
    <fullcount>2</fullcount>
</feed>

Say for example I just wanted to get the value of <fullcount> from there. I'm sure there is probably some super simple explanation!

Thanks!

Look here about namespaces.
  • 2 weeks later...
Posted (edited)

My Server will be down beginning January 18, 2008 for maintenance. The CPU fan has failed.

Ok, it's back up.

Edited by eltorro
Posted (edited)

Hello out there.

I've got some errors coming up and I am unsure as to why they are coming up. I'm trying to use the MDI version of the XMLDOM file, and it's erroring out on me.

Here is the Error message:

_XMLMdiDOM.au3 (276) : ==> Array variable subscript badly formatted.:
I have the same problem. My code is very simple:

CODE
#Include <_XMLMdiDOM.au3>

$out_open = _XMLCreateFile("c:\testout.xml", "dita")

The error message isolates this line in _XMLMdiDOM.au3, within the _XMLCreateFile function:

Local $retval, $fe, $objPI, $objDoc[$oIndex], $rootElement

and points to $oIndex as the offending part.

I replaced the line with

Local $retval, $fe, $objPI, $rootElement

and the fiunction seems to work. However, as a newbie, I've no idea whether this fix is OK.

Edited by AJO
Posted (edited)

I have the same problem. My code is very simple:

CODE
#Include <_XMLMdiDOM.au3>

#Include <Array.au3>

$out_open = _XMLCreateFile("c:\testout.xml", "dita")

I was able to edit this once, but I can't see how to do it again, so I'll reply. I wanted to add:

Thanks for doing this!

Also I wanted to explain why I'm trying to use _XMLMdiDOM.au3. In a previous post, someone said they wanted to read nodes from one file and write them to another, and the advice they received was to use _XMLMdiDOM.au3. I want to do the same, so I picked it up and tried it. But I just noticed that it hasn't been updated since 2006 -- is it superseded by the latest _XMLDOMWrapper?

By the way, I've updated the example code -- I did include Array.au3.

Edited by AJO
Posted

Please help me understand the _XMLGetField function, it is not returning the field in my sample. For each Hotfix in the XML I want it to return the filename.

Here is the XML:

<Hotfix_List>

<Build>

<title>Hotfix Install for Windows XP</title>

<version>1.0</version>

</Build>

<Hotfix>

<name>KB885836</name>

<filename>"WindowsXP-KB885523-x86-enu.exe"</filename>

<switches>/quiet /passive /norestart</switches>

</Hotfix>

<Hotfix>

<name>KB887742</name>

<filename>WindowsXP-KB885836-x86-ENU.exe</filename>

<switches>/quiet /passive /norestart</switches>

</Hotfix>

<Hotfix>

<name>KB885836</name>

<filename>WindowsXP-KB887742-x86-ENU.exe</filename>

<switches>/quiet /passive /norestart</switches>

</Hotfix>

</Hotfix_List>

Here is the Code:

#include <_XMLDomWrapper.au3>

#include <Array.au3>

$sXMLFile = "Hotfix.xml"

$result = _XMLFileOpen($sXMLFile)

if $result = 0 then Exit

Local $nodeCount = _XMLGetNodeCount ("//Hotfix_List/*")

If $nodeCount > 0 Then

Local $x, $z, $sRet = _XMLSelectNodes ("//Hotfix_List/Hotfix")

If IsArray($sRet) Then

For $x = 1 To $sRet[0]

If $sRet[$x] = "Hotfix" Then

msgbox(0,"Test",$sRet[$x])

msgbox(0,"Test","Filename: " & _XMLGetField("//Hotfix_List/Hotfix/filename"))

EndIf

Next

EndIf

EndIf

Exit

Posted

Here you go:

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

$sXMLFile = "Hotfix.xml"

$result = _XMLFileOpen($sXMLFile)
If $result = 0 Then Exit

$sRet = _XMLSelectNodes("//Hotfix")

For $X = 1 to $sRet[0]
    ConsoleWrite("Hotfix: " & _GetFirstValue("//Hotfix[" & $X & "]/name") & @CRLF & "Filename: " & _GetFirstValue("//Hotfix[" & $X & "]/filename") & @CRLF)
Next

;Get the first real value returned from the _XMLGetValue() return array.
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Posted

Here you go:

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

$sXMLFile = "Hotfix.xml"

$result = _XMLFileOpen($sXMLFile)
If $result = 0 Then Exit

$sRet = _XMLSelectNodes("//Hotfix")

For $X = 1 to $sRet[0]
    ConsoleWrite("Hotfix: " & _GetFirstValue("//Hotfix[" & $X & "]/name") & @CRLF & "Filename: " & _GetFirstValue("//Hotfix[" & $X & "]/filename") & @CRLF)
Next

;Get the first real value returned from the _XMLGetValue() return array.
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Perfect

Your the King! Thanks.

Posted (edited)

...man I like dealing with the registry and INI files better....

Any way, need to read all the "name" values for each child node under "SWD/Advertisements". All of those children have the same name of "Advertisement" All of the examples I have seen have a known value of "name" and getting the rest of the values is simple. I have tried looking through all the posts (holy cow there are a lot) and still haven't seen one that fits my issue. How do I go about getting all of the "name" values...

_XMLGetAttrib ("/SWD/Advertisements/Advertisement", "name")

...That only brings back the first one when I can have almost hundreds of these "/SWD/Advertisements/Advertisement" nodes Below is a sample xml:

<SWD>
    <Advertisements>
        <Advertisement name="Some Program Name" package="{guid 1}">
            <!-- bla bla bla -->
        </Advertisement>
        <Advertisement name="Other program" package="{guid 2}">
            <!-- bla bla bla -->
        </Advertisement>
        <Advertisement name="My Program" package="{guid 3}">
            <!-- bla bla bla -->
        </Advertisement>
    </Advertisements>
    <Packages>
        <Package name="Some Program Name">
            <!-- bla bla bla -->
        </Package>
        <Package name="Other program">
            <!-- bla bla bla -->
        </Package>
        <Package name="My Program">
            <!-- bla bla bla -->
        </Package>
    </Packages>
    <Programs>
        <Program name="Some Program Name">
            <!-- bla bla bla -->
        </Program>
        <Program name="Other program">
            <!-- bla bla bla -->
        </Program>
        <Program name="My Program">
            <!-- bla bla bla -->
        </Program>
    </Programs>
</SWD>

Thanks again for the help and amazing and way cool functions edelator!!! Bet you didn't know what you were getting into when you put this out there ha? ;-)

Edit - I will also need to read the "package" to deal with the file system later

Edited by masonje
Posted

This is pretty easy. There is a big learning curve for the way this UDF works IMHO. I have a lot more experience using Actionscript XML and this is completely different.

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

$sXMLFile = "advertisements.xml"

$result = _XMLFileOpen($sXMLFile)
If $result = 0 Then Exit

$path = "//Advertisements"

;Retrieve only Advertisement subnodes
$nodesArray = _XMLSelectNodes($path & "/Advertisement")

;Retrieve all subnodes
;$nodesArray = _XMLSelectNodes($path & "/*")

;_ArrayDisplay($nodesArray)

For $X = 1 to $nodesArray[0]
    ConsoleWrite(_XMLGetAttrib($path & "/Advertisement[" & $X & "]", "name") & @CRLF)
Next

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...