Jump to content

Recommended Posts

Posted (edited)

Hi, this piece of non-sense doesn't even gives an xml file as example https://msdn.microsoft.com/en-us/library/ms754523(v=vs.85).aspx

How do I call and retrieve all the matches node?

<?xml version="1.0"?>
<!DOCTYPE compactdiscs SYSTEM "cds.dtd">
<compactdiscs>
  <compactdisc>
    <artist type="individual">Frank Sinatra</artist>
    <title numberoftracks="4">In The Wee Small Hours</title>
   <tracks>
      <track>In The Wee Small Hours</track>
      <track>Mood Indigo</track>
      <track>Glad To Be Unhappy</track>
      <track>I Get Along Without You Very Well</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
  <compactdisc>
    <artist type="band">The Offspring</artist>
    <title numberoftracks="5">Americana</title>
   <tracks>
      <track>Welcome</track>
      <track>Have You Ever</track>
      <track>Staring At The Sun</track>
      <track>Pretty Fly (For A White Guy)</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
</compactdiscs>

For example, track nodes, how shoud I do it?

Tried like this but I get an error Variable must be of type "Object"

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks/track")
For $oNode In $oNodes.childnodes
    ConsoleWrite($oNode.text & @CRLF)
Next

How should I been doing it?

EDIT: This mixes everything

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks/track")
Do
    $oNode = $oNodes.nextNode()
    $t = $oNode.text
    ConsoleWrite($t & @CRLF)
Until @error Or $t = ''

 is there a way to do this like this:

1st return a array of objects with 2 rows ubound($tracks)=2
2nd return the matches of loop{$tracks.item(x).nextNode()}

EDIT2: I think this is a small step to crawl a xml

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks")
For $oNode in $oNodes
    $childs = $oNode.childNodes
    For $child in $childs
        ConsoleWrite($child.tagName&" = "&$child.text@LF)
    Next
Next

My doubt now is, how can I recursive for child nodes in every single node? I'm in nodeception right now

Edited by Kyan

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted (edited)

some improvements

;~ https://msdn.microsoft.com/en-us/library/aa468547.aspx

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir & "\example.xml")
ConsoleWrite("$oXml.ReadyState = " & $oXml.ReadyState & @LF)

Local $oNodes = $oXML.selectNodes("//tracks")
Local $oChilds

For $oNode In $oNodes
    $oChilds = $oNode.childNodes
    For $oChild In $oChilds
        ConsoleWrite($oChild.tagName & " = " & $oChild.text & @LF)
        ConsoleWrite($oChild.tagName & " = " & $oChild.text & @LF)
        ConsoleWrite($oChild.parentNode.nodeName & ':' & $oChild.nodeValue & @CRLF)
    Next
Next


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

thanks mLipok for helping out :)
is only returning the readystate :|

  Reveal hidden contents

EDIT: Something fishy is going on

ConsoleWrite("outside"&@LF)
For $oNode In $oNodes
  ConsoleWrite("inside"&@LF)
  ConsoleWrite(IsObj($oNode)&@LF)
  $oChilds = $oNode.childNodes

output

$oXml.ReadyState = [4] The request is complete
outside

EDIT2: I'm not figuring out what is going on :\

ConsoleWrite($oNodes.nodeName&@LF) ->Gives err 0x80020006
ConsoleWrite($oNodes.firstChild.nodeName&@LF) ->Gives err 0x80020006
ConsoleWrite($oNodes.item(0).nodeName&@LF) ->BIS

:blink:

EDIT3: I give up, if there was a ShowDOMList function it would totally help out :( (like _ArrayDisplay but for DOM objects)
 

Edited by Kyan

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted

Bump peri bump

Any tip how to recursively check for sub nodes in each read node? and how would I return those values in a orderly fashion?

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted

Try this:

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

_XMLFileOpen(@ScriptDir & "\example.xml")
MsgBox(0, '@error', @extended)
$aNodes = _XMLGetChildNodes("/compactdiscs")
For $iNode = 1 To $aNodes[0]
    $POLY_COORDS = _XMLGetChildren("compactdiscs/" & $aNodes[$iNode])
    ConsoleWrite("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]" & @CRLF)
    $ID = _XMLGetAttrib("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]", "id")
    MsgBox(0, $ID, StringReplace($POLY_COORDS[1][1], @TAB, ""))
Next

But remove this line from example.xml

<!DOCTYPE compactdiscs SYSTEM "cds.dtd">

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

sorry for asking, but where do I find the _XMLDomWrapper.au3? I searched on examples but no topics were found .\

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I removed the line but it gives me this error from the msgbox -2146697210

I used your last code:
 

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

_XMLFileOpen(@ScriptDir & "\example.xml")
MsgBox(0, '@error', @extended)
$aNodes = _XMLGetChildNodes("/compactdiscs")
For $iNode = 1 To $aNodes[0]
    $POLY_COORDS = _XMLGetChildren("compactdiscs/" & $aNodes[$iNode])
    ConsoleWrite("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]" & @CRLF)
    $ID = _XMLGetAttrib("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]", "id")
    MsgBox(0, $ID, StringReplace($POLY_COORDS[1][1], @TAB, ""))
Next

and example.xml had been edited to

<?xml version="1.0"?>
<compactdiscs>
  <compactdisc>
  <artist type="individual">Frank Sinatra</artist>
  <title numberoftracks="4">In The Wee Small Hours</title>
   <tracks>
    <track>In The Wee Small Hours</track>
    <track>Mood Indigo</track>
    <track>Glad To Be Unhappy</track>
    <track>I Get Along Without You Very Well</track>
   </tracks>
  <price>$12.99</price>
  </compactdisc>
  <compactdisc>
  <artist type="band">The Offspring</artist>
  <title numberoftracks="5">Americana</title>
   <tracks>
    <track>Welcome</track>
    <track>Have You Ever</track>
    <track>Staring At The Sun</track>
    <track>Pretty Fly (For A White Guy)</track>
   </tracks>
  <price>$12.99</price>
  </compactdisc>
</compactdiscs>

 

Edited by Kyan

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

  • 2 weeks later...
Posted
  On 4/29/2015 at 6:58 AM, Kyan said:

Hi, this piece of non-sense doesn't even gives an xml file as example https://msdn.microsoft.com/en-us/library/ms754523(v=vs.85).aspx

How do I call and retrieve all the matches node?

<?xml version="1.0"?>
<!DOCTYPE compactdiscs SYSTEM "cds.dtd">
<compactdiscs>
  <compactdisc>
    <artist type="individual">Frank Sinatra</artist>
    <title numberoftracks="4">In The Wee Small Hours</title>
   <tracks>
      <track>In The Wee Small Hours</track>
      <track>Mood Indigo</track>
      <track>Glad To Be Unhappy</track>
      <track>I Get Along Without You Very Well</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
  <compactdisc>
    <artist type="band">The Offspring</artist>
    <title numberoftracks="5">Americana</title>
   <tracks>
      <track>Welcome</track>
      <track>Have You Ever</track>
      <track>Staring At The Sun</track>
      <track>Pretty Fly (For A White Guy)</track>
   </tracks>
    <price>$12.99</price>
  </compactdisc>
</compactdiscs>

For example, track nodes, how shoud I do it?

Tried like this but I get an error Variable must be of type "Object"

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks/track")
For $oNode In $oNodes.childnodes
    ConsoleWrite($oNode.text & @CRLF)
Next

How should I been doing it?

EDIT: This mixes everything

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks/track")
Do
    $oNode = $oNodes.nextNode()
    $t = $oNode.text
    ConsoleWrite($t & @CRLF)
Until @error Or $t = ''

 is there a way to do this like this:

1st return a array of objects with 2 rows ubound($tracks)=2
2nd return the matches of loop{$tracks.item(x).nextNode()}

EDIT2: I think this is a small step to crawl a xml

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load(@DesktopDir&"\example.xml")

$oNodes = $oXML.selectNodes("//tracks")
For $oNode in $oNodes
    $childs = $oNode.childNodes
    For $child in $childs
        ConsoleWrite($child.tagName&" = "&$child.text@LF)
    Next
Next

My doubt now is, how can I recursive for child nodes in every single node? I'm in nodeception right now

​You can use your XML example with this code:

;~ https://msdn.microsoft.com/en-us/library/aa468547.aspx

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $objDoc = ObjCreate("Msxml2.DOMDocument.4.0")

$objDoc.validateOnParse = False
$objDoc.load(@ScriptDir & "\example.xml")
_XML_ErrorParser($objDoc)
$objDoc.setProperty("SelectionLanguage", "XPath")
_XML_ErrorParser($objDoc)
$objDoc.setProperty("SelectionNamespaces", '')
_XML_ErrorParser($objDoc)

ConsoleWrite("$objDoc.ReadyState = " & $objDoc.ReadyState & @LF)

Local $oCurrNode = $objDoc.documentElement.childNodes.item(1);
ConsoleWrite($oCurrNode.xml & @CRLF);

;~ Local $oNodes = $objDoc.SelectNodes("/compactdiscs/compactdisc/tracks")
Local $oNodes = $objDoc.SelectNodes("/compactdiscs/compactdisc/tracks")
;~ _XML_ErrorParser($objDoc)

;~ MsgBox(0, '', $oNodes.xml)
If IsObj($oNodes) Then
;~  https://msdn.microsoft.com/en-us/library/ms757852(v=vs.85).aspx
    MsgBox(0, '1', $oNodes.expr)
    MsgBox(0, '2', $oNodes.length)
    MsgBox(0, '3', $oNodes.context)
    Local $iStep = 1
    For $oNode In $oNodes
        ConsoleWrite('$iStep  = ' & $iStep & @CRLF)
        $iStep += 1
        ConsoleWrite($oNode.nodeName & ':' & $oNode.nodeValue & @CRLF)
        ConsoleWrite($oNode.nodeType & ':' & $oNode.nodeValue & @CRLF)
    Next
EndIf

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc


; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_ErrorParser
; Description ...: Parse Error to Console
; Syntax ........: _XML_ErrorParser(Byref $objDoc)
; Parameters ....: $objDoc              - [in/out] an object.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://msdn.microsoft.com/en-us/library/ms767720(v=vs.85).aspx , https://msdn.microsoft.com/en-us/library/ms757019(v=vs.85).aspx
; Example .......: No
; ===============================================================================================================================
Func _XML_ErrorParser(ByRef $objDoc)
    If $objDoc.parseError.errorCode <> 0 Then
        ConsoleWrite('IXMLDOMParseError errorCode = ' & $objDoc.parseError.errorCode & @CRLF) ; Contains the error code of the last parse error.
        ConsoleWrite('IXMLDOMParseError filepos = ' & $objDoc.parseError.filepos & @CRLF) ; Contains the absolute file position where the error occurred.
        ConsoleWrite('IXMLDOMParseError line = ' & $objDoc.parseError.line & @CRLF) ; Specifies the line number that contains the error.
        ConsoleWrite('IXMLDOMParseError linepos = ' & $objDoc.parseError.linepos & @CRLF) ; Contains the character position within the line where the error occurred.
        ConsoleWrite('IXMLDOMParseError reason = ' & $objDoc.parseError.reason & @CRLF) ; Describes the reason for the error.
        ConsoleWrite('IXMLDOMParseError srcText = ' & $objDoc.parseError.srcText & @CRLF) ; Returns the full text of the line containing the error.
        ConsoleWrite('IXMLDOMParseError url = ' & $objDoc.parseError.url & @CRLF) ; Contains the URL of the XML document containing the last error.
        ConsoleWrite('.............................................................................' & @CRLF)
    EndIf

EndFunc   ;==>_XML_ErrorParser

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 2 months later...
Posted
  On 5/2/2015 at 8:37 PM, mLipok said:

Try this:

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

_XMLFileOpen(@ScriptDir & "\example.xml")
MsgBox(0, '@error', @extended)
$aNodes = _XMLGetChildNodes("/compactdiscs")
For $iNode = 1 To $aNodes[0]
    $POLY_COORDS = _XMLGetChildren("compactdiscs/" & $aNodes[$iNode])
    ConsoleWrite("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]" & @CRLF)
    $ID = _XMLGetAttrib("/compactdiscs/" & $aNodes[$iNode] & "[" & $iNode & "]", "id")
    MsgBox(0, $ID, StringReplace($POLY_COORDS[1][1], @TAB, ""))
Next

I don't understand how this could work. In _XMLDomWrapper.au3 (Global Const $_XMLUDFVER = "1.0.3.98")  the functions _XMLGetChildNodes and  _XMLGetChildren require two args eg., '(Func _XMLGetChildren(ByRef $objDoc, $strXPath)' but this example only supplies one argument. Perhaps you are working with an older version of _XMLDomWrapper?

I've been struggling for days trying to get the various usage examples on the forum for _XMLDomWrapper to work but they all fail due to this same incompatibility. Perhaps i am missing something obvious but I'm afraid I can't see it. Any help would be appreciated.

Phil Seakins

Posted
  On 8/3/2015 at 4:06 PM, pseakins said:

I don't understand how this could work. In _XMLDomWrapper.au3 (Global Const $_XMLUDFVER = "1.0.3.98")  the functions _XMLGetChildNodes and  _XMLGetChildren require two args eg., '(Func _XMLGetChildren(ByRef $objDoc, $strXPath)' but this example only supplies one argument. Perhaps you are working with an older version of _XMLDomWrapper?

Yes. When I post a link in post #7 then this was "1.0.3.87"
Actually I'm on vacation , regardless of that I have some other work to do.
I'm not a "master of XML" but I can back to XML in two weeks, when I was a plan to back to work with my XMLDomWrapper update.
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/3/2015 at 11:19 PM, mLipok said:

Yes. When I post a link in post #7 then this was "1.0.3.87"
Actually I'm on vacation , regardless of that I have some other work to do.
I'm not a "master of XML" but I can back to XML in two weeks, when I was a plan to back to work with my XMLDomWrapper update.
 

Yes, thank you. There is no hurry for me, I found out how to use the new UDF. It has undocumented, code breaking changes. To use it you need to add the global variable $objDoc as the first argument in the call to the changed functions.

Phil Seakins

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...