Kyan

How to use .SelectNodes on XMLDOM?

12 posts in this topic

#1 ·  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

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

Share this post


Link to post
Share on other sites



#2 ·  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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

;~ 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 & "] " & _ReadyStates($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.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

Func _ReadyStates($iRState)
    Switch $iRState
        Case 0
            Return "The request is not initialized"
        Case 1
            Return "The request has been set up"
        Case 2
            Return "The request has been sent"
        Case 3
            Return "The request is in process"
        Case 4
            Return "The request is complete"
    EndSwitch
EndFunc

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

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

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

 

1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#8 ·  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

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

Share this post


Link to post
Share on other sites

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

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

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