Jump to content

Recommended Posts

Posted (edited)

@mLipok This document will not be parsed, unless you remove the link tag:

<html>
  <head>
    <meta charset="utf-8">
    <link href="main.css" rel="stylesheet">
    <title>My test page</title>
  </head>
  <body>
    <p>This is my page</p>
  </body>
</html>

 

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted

@TheDcoder so you post XML but where you post your au3 code to reproduce your problem ?

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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Posted (edited)

@mLipok Sorry, I was on Linux and I was planning to write a reproducer script when I switch to Windows. Here is the script:

#include "XML\XML.au3"

Global $oErrorHandler = ObjEvent("AutoIt.Error", ErrFunc_CustomUserHandler_MAIN)
_XML_ComErrorHandler_UserFunction(ErrFunc_CustomUserHandler_XML)

Main()

Func Main()
    Local $sHtml = '<html><head><link href="main.css" rel="stylesheet"></head></html>'
    Local $oXMLDoc = _XML_CreateDOMDocument(Default)
    ConsoleWrite('+> Create DOMDocument: ' & XML_My_ErrorParser(@error) & @CRLF)
    _XML_LoadXML($oXMLDoc, $sHtml, 'xhtml', False)
    ConsoleWrite('+> Load XML: ' & XML_My_ErrorParser(@error) & @CRLF)
    ConsoleWrite(_XML_ErrorParser_GetDescription($oXMLDoc) & @CRLF)
    ; ...
EndFunc

Func ErrFunc_CustomUserHandler_MAIN($oError)
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : MainScript ==> 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

Func ErrFunc_CustomUserHandler_XML($oError)
    ConsoleWrite(@ScriptDir & '\XMLWrapperEx.au3' & " (" & $oError.scriptline & ") : UDF ==> 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

; #FUNCTION# ====================================================================================================================
; Name ..........: XML_My_ErrorParser
; Description ...: Changing $XML_ERR_ ... to human readable description
; Syntax ........: XML_My_ErrorParser($iXMLWrapper_Error, $iXMLWrapper_Extended)
; Parameters ....: $iXMLWrapper_Error   - an integer value.
;                  $iXMLWrapper_Extended           - an integer value.
; Return values .: description as string
; Author ........: mLipok
; Modified ......:
; Remarks .......: This function is only example of how user can parse @error and @extended to human readable description
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func XML_My_ErrorParser($iXMLWrapper_Error, $iXMLWrapper_Extended = 0)
    Local $sErrorInfo = ''
    Switch $iXMLWrapper_Error
        Case $XML_ERR_SUCCESS
            $sErrorInfo = '$XML_ERR_SUCCESS=' & $XML_ERR_SUCCESS & @CRLF & 'All is ok.'
        Case $XML_ERR_GENERAL
            $sErrorInfo = '$XML_ERR_GENERAL=' & $XML_ERR_GENERAL & @CRLF & 'The error which is not specifically defined.'
        Case $XML_ERR_COMERROR
            $sErrorInfo = '$XML_ERR_COMERROR=' & $XML_ERR_COMERROR & @CRLF & 'COM ERROR OCCURED. Check @extended and your own error handler function for details.'
        Case $XML_ERR_ISNOTOBJECT
            $sErrorInfo = '$XML_ERR_ISNOTOBJECT=' & $XML_ERR_ISNOTOBJECT & @CRLF & 'No object passed to function'
        Case $XML_ERR_INVALIDDOMDOC
            $sErrorInfo = '$XML_ERR_INVALIDDOMDOC=' & $XML_ERR_INVALIDDOMDOC & @CRLF & 'Invalid object passed to function'
        Case $XML_ERR_INVALIDATTRIB
            $sErrorInfo = '$XML_ERR_INVALIDATTRIB=' & $XML_ERR_INVALIDATTRIB & @CRLF & 'Invalid object passed to function.'
        Case $XML_ERR_INVALIDNODETYPE
            $sErrorInfo = '$XML_ERR_INVALIDNODETYPE=' & $XML_ERR_INVALIDNODETYPE & @CRLF & 'Invalid object passed to function.'
        Case $XML_ERR_OBJCREATE
            $sErrorInfo = '$XML_ERR_OBJCREATE=' & $XML_ERR_OBJCREATE & @CRLF & 'Object can not be created.'
        Case $XML_ERR_NODECREATE
            $sErrorInfo = '$XML_ERR_NODECREATE=' & $XML_ERR_NODECREATE & @CRLF & 'Can not create Node - check also COM Error Handler'
        Case $XML_ERR_NODEAPPEND
            $sErrorInfo = '$XML_ERR_NODEAPPEND=' & $XML_ERR_NODEAPPEND & @CRLF & 'Can not append Node - check also COM Error Handler'
        Case $XML_ERR_PARSE
            $sErrorInfo = '$XML_ERR_PARSE=' & $XML_ERR_PARSE & @CRLF & 'Error: with Parsing objects, .parseError.errorCode=' & $iXMLWrapper_Extended & ' Use _XML_ErrorParser_GetDescription() for get details.'
        Case $XML_ERR_PARSE_XSL
            $sErrorInfo = '$XML_ERR_PARSE_XSL=' & $XML_ERR_PARSE_XSL & @CRLF & 'Error with Parsing XSL objects .parseError.errorCode=' & $iXMLWrapper_Extended & ' Use _XML_ErrorParser_GetDescription() for get details.'
        Case $XML_ERR_LOAD
            $sErrorInfo = '$XML_ERR_LOAD=' & $XML_ERR_LOAD & @CRLF & 'Error opening specified file.'
        Case $XML_ERR_SAVE
            $sErrorInfo = '$XML_ERR_SAVE=' & $XML_ERR_SAVE & @CRLF & 'Error saving file.'
        Case $XML_ERR_PARAMETER
            $sErrorInfo = '$XML_ERR_PARAMETER=' & $XML_ERR_PARAMETER & @CRLF & 'Wrong parameter passed to function.'
        Case $XML_ERR_ARRAY
            $sErrorInfo = '$XML_ERR_ARRAY=' & $XML_ERR_ARRAY & @CRLF & 'Wrong array parameter passed to function. Check array dimension and conent.'
        Case $XML_ERR_XPATH
            $sErrorInfo = '$XML_ERR_XPATH=' & $XML_ERR_XPATH & @CRLF & 'XPath syntax error - check also COM Error Handler.'
        Case $XML_ERR_NONODESMATCH
            $sErrorInfo = '$XML_ERR_NONODESMATCH=' & $XML_ERR_NONODESMATCH & @CRLF & 'No nodes match the XPath expression'
        Case $XML_ERR_NOCHILDMATCH
            $sErrorInfo = '$XML_ERR_NOCHILDMATCH=' & $XML_ERR_NOCHILDMATCH & @CRLF & 'There is no Child in nodes matched by XPath expression.'
        Case $XML_ERR_NOATTRMATCH
            $sErrorInfo = '$XML_ERR_NOATTRMATCH=' & $XML_ERR_NOATTRMATCH & @CRLF & 'There is no such attribute in selected node.'
        Case $XML_ERR_DOMVERSION
            $sErrorInfo = '$XML_ERR_DOMVERSION=' & $XML_ERR_DOMVERSION & @CRLF & 'DOM Version: ' & 'MSXML Version ' & $iXMLWrapper_Extended & ' or greater required for this function'
        Case $XML_ERR_EMPTYCOLLECTION
            $sErrorInfo = '$XML_ERR_EMPTYCOLLECTION=' & $XML_ERR_EMPTYCOLLECTION & @CRLF & 'Collections of objects was empty'
        Case $XML_ERR_EMPTYOBJECT
            $sErrorInfo = '$XML_ERR_EMPTYOBJECT=' & $XML_ERR_EMPTYOBJECT & @CRLF & 'Object is empty'
        Case Else
            $sErrorInfo = '=' & $iXMLWrapper_Error & @CRLF & 'NO ERROR DESCRIPTION FOR THIS @error'
    EndSwitch

    Local $sExtendedInfo = ''
    Switch $iXMLWrapper_Error
        Case $XML_ERR_COMERROR, $XML_ERR_NODEAPPEND, $XML_ERR_NODECREATE
            $sExtendedInfo = 'COM ERROR NUMBER (@error returned via @extended) =' & $iXMLWrapper_Extended
        Case $XML_ERR_PARAMETER
            $sExtendedInfo = 'This @error was fired by parameter: #' & $iXMLWrapper_Extended
        Case Else
            Switch $iXMLWrapper_Extended
                Case $XML_EXT_DEFAULT
                    $sExtendedInfo = '$XML_EXT_DEFAULT=' & $XML_EXT_DEFAULT & @CRLF & 'Default - Do not return any additional information'
                Case $XML_EXT_XMLDOM
                    $sExtendedInfo = '$XML_EXT_XMLDOM=' & $XML_EXT_XMLDOM & @CRLF & '"Microsoft.XMLDOM" related Error'
                Case $XML_EXT_DOMDOCUMENT
                    $sExtendedInfo = '$XML_EXT_DOMDOCUMENT=' & $XML_EXT_DOMDOCUMENT & @CRLF & '"Msxml2.DOMDocument" related Error'
                Case $XML_EXT_XSLTEMPLATE
                    $sExtendedInfo = '$XML_EXT_XSLTEMPLATE=' & $XML_EXT_XSLTEMPLATE & @CRLF & '"Msxml2.XSLTemplate" related Error'
                Case $XML_EXT_SAXXMLREADER
                    $sExtendedInfo = '$XML_EXT_SAXXMLREADER=' & $XML_EXT_SAXXMLREADER & @CRLF & '"MSXML2.SAXXMLReader" related Error'
                Case $XML_EXT_MXXMLWRITER
                    $sExtendedInfo = '$XML_EXT_MXXMLWRITER=' & $XML_EXT_MXXMLWRITER & @CRLF & '"MSXML2.MXXMLWriter" related Error'
                Case $XML_EXT_FREETHREADEDDOMDOCUMENT
                    $sExtendedInfo = '$XML_EXT_FREETHREADEDDOMDOCUMENT=' & $XML_EXT_FREETHREADEDDOMDOCUMENT & @CRLF & '"Msxml2.FreeThreadedDOMDocument" related Error'
                Case $XML_EXT_XMLSCHEMACACHE
                    $sExtendedInfo = '$XML_EXT_XMLSCHEMACACHE=' & $XML_EXT_XMLSCHEMACACHE & @CRLF & '"Msxml2.XMLSchemaCache." related Error'
                Case $XML_EXT_STREAM
                    $sExtendedInfo = '$XML_EXT_STREAM=' & $XML_EXT_STREAM & @CRLF & '"ADODB.STREAM" related Error'
                Case $XML_EXT_ENCODING
                    $sExtendedInfo = '$XML_EXT_ENCODING=' & $XML_EXT_ENCODING & @CRLF & 'Encoding related Error'
                Case Else
                    $sExtendedInfo = '$iXMLWrapper_Extended=' & $iXMLWrapper_Extended & @CRLF & 'NO ERROR DESCRIPTION FOR THIS @extened'
            EndSwitch
    EndSwitch
    ; return back @error and @extended for further debuging
    Return SetError($iXMLWrapper_Error, $iXMLWrapper_Extended, _
            '@error description:' & @CRLF & _
            $sErrorInfo & @CRLF & _
            @CRLF & _
            '@extended description:' & @CRLF & _
            $sExtendedInfo & @CRLF & _
            '')

EndFunc    ;==>XML_My_ErrorParser

You can see that in the output it says "End tag 'head' does not match the start tag 'link'", which means the parser is unable to deal with single/void/non-closing tags :(

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

I guess msxml is not made for parsing HTML... problems start popping up as soon as I start fixing them :(. Here are some functions people might find useful if they are working with HTML...

; Use this function to remove the contents of script tags (some symbols confuse the parser)
Func StripScriptTagContent(ByRef $sHtml)
    $sHtml = StringRegExpReplace($sHtml, '(*UCP)(?si)<script.*?>.*?<\/script>', '<script>Truncated</script>')
EndFunc

; Use this function to automatically generate end tags for void tags, a bad workaround and will generate invalid HTML, but it works for analysis purposes
Func CleanseVoidTags(ByRef $sHtml)
    Local Static $aVoidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']
    For $sTag In $aVoidTags
        $sHtml = StringRegExpReplace($sHtml, '(*UCP)(?si)(<' & $sTag & ' .*?>)', '\0</' & $sTag & '>')
    Next
EndFunc

The parser has started to complain about undefined entities (Reference to undefined entity 'nbsp').

I guess I will write my own parser for now... sigh.

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • 1 month later...
Posted

@mLipok Can I generate a XML file with doctype declare such as '<!DOCTYPE SCHEMA SYSTEM "HGWSPZJK.dtd">' by using XML.AU3

the whole xml file like as follow:

<?xml version="1.0" encoding="GBK"?>

<!DOCTYPE SCHEMA SYSTEM "HGWSPZJK.dtd"> ;I can not generate this line

<SCHEMA CRC="HGWSPZ201808_9131011571786229XM_CRC.XML" SSSQ="201808" CHSNAME="海关完税凭证抵扣清单" NAME="HGWSPZ">


<TAXPAYER CJRMC="西格玛奥德里奇(上海)贸易有限公司" CJRDM="9131011571786229XM" CJLX="DKZK" RECORDCOUNT="411" SBRQ="2018-08-31" NSRMC="西格玛奥德里奇(上海)贸易有限公司" SWSBH="9131011571786229XM">


<Records>

<Record BZ="" JKKADM="2244" JKKAMC="上海快件" SE="5907.82" TFRQ="2018-08-23" FPHM="224420181000752586-L02"/>

<Record BZ="" JKKADM="2244" JKKAMC="上海快件" SE="4742.4" TFRQ="2018-08-21" FPHM="224420181000743016-L01"/>

<Record BZ="" JKKADM="2244" JKKAMC="上海快件" SE="18720" TFRQ="2018-08-14" FPHM="224420181000719215-L01"/>

<Record BZ="" JKKADM="2244" JKKAMC="上海快件" SE="9575.2" TFRQ="2018-08-14" FPHM="224420181000719204-L01"/>

</Records>

</TAXPAYER>

</SCHEMA>

someone said that use CreateDocumentType  https://docs.microsoft.com/zh-cn/dotnet/api/system.xml.xmldocument.createdocumenttype?redirectedfrom=MSDN&view=netframework-4.7.2#System_Xml_XmlDocument_CreateDocumentType_System_String_System_String_System_String_System_String_

someone said that use loadxml

I confused that  can I only use FileWrite ()  write the string as above and save as test.xml 

thanks

Posted (edited)

try to focus on this example:

If you solve your problem please share solution, if you have further question just ask.

EDITE: proper URL to example.

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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

  • 3 months later...
Posted (edited)

Hi @mLipok,

Thank you so much for the work you have done with XML.au3. I typically do not message the authors of UDFs, but I have struggled with this issue for weeks. I do not have a problem retrieving the results of an API call to FedEx, my problem is traversing the nodes.  Can you please post a SOAP example to your XML_Example_XML_Files, or just assist with the issue I am having.  Attached is the XML response and below are the code snippets.  Current using XMLDomWrapper.au3, but plan to shift to XML.au3.

Example: I cannot get to node: 

/SOAP-ENV:Envelope/SOAP-ENV:Body/TrackReply/CompletedTrackDetails/TrackDetails/Service/Type

THANK YOU IN ADVANCE!! 

-------------------------------------------------------------------------------------------------------------------------------------------   

$sPD = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v16="http://fedex.com/ws/track/v16">' & @CRLF & _
            '<soapenv:Header/>' & @CRLF & _
            '<soapenv:Body>' & @CRLF & _
            '<v16:TrackRequest>' & @CRLF & _
            '<v16:WebAuthenticationDetail>' & @CRLF & _
            '<v16:ParentCredential>' & @CRLF & _
            '<v16:Key>XXXXXXXXXXXXX</v16:Key>' & @CRLF & _
            '<v16:Password>XXXXXXXXXXXXXXXX</v16:Password>' & @CRLF & _
            '</v16:ParentCredential>' & @CRLF & _
            '<v16:UserCredential>' & @CRLF & _
            '<v16:Key>XXXXXXXXXXXXXXX</v16:Key>' & @CRLF & _
            '<v16:Password>XXXXXXXXXXXXXXXXXXX</v16:Password>' & @CRLF & _
            '</v16:UserCredential>' & @CRLF & _
            '</v16:WebAuthenticationDetail>' & @CRLF & _
            '<v16:ClientDetail>' & @CRLF & _
            '<v16:AccountNumber>XXXXXXXXXXX</v16:AccountNumber>' & @CRLF & _
            '<v16:MeterNumber>XXXXXXXXXXXX</v16:MeterNumber>' & @CRLF & _
            '</v16:ClientDetail>' & @CRLF & _
            '<v16:TransactionDetail>' & @CRLF & _
            '<v16:CustomerTransactionId>Track By Number_v16</v16:CustomerTransactionId>' & @CRLF & _
            '<v16:Localization>' & @CRLF & _
            '<v16:LanguageCode>EN</v16:LanguageCode>' & @CRLF & _
            '<v16:LocaleCode>US</v16:LocaleCode>' & @CRLF & _
            '</v16:Localization>' & @CRLF & _
            '</v16:TransactionDetail>' & @CRLF & _
            '<v16:Version>' & @CRLF & _
            '<v16:ServiceId>trck</v16:ServiceId>' & @CRLF & _
            '<v16:Major>16</v16:Major>' & @CRLF & _
            '<v16:Intermediate>0</v16:Intermediate>' & @CRLF & _
            '<v16:Minor>0</v16:Minor>' & @CRLF & _
            '</v16:Version>' & @CRLF & _
            '<v16:SelectionDetails>' & @CRLF & _
            '<v16:CarrierCode>FDXE</v16:CarrierCode>' & @CRLF & _
            '<v16:PackageIdentifier>' & @CRLF & _
            '<v16:Type>TRACKING_NUMBER_OR_DOORTAG</v16:Type>' & @CRLF & _
            '<v16:Value>' & $Tracking_Number & '</v16:Value>' & @CRLF & _
            '</v16:PackageIdentifier>' & @CRLF & _
            '<v16:ShipmentAccountNumber/>' & @CRLF & _
            '<v16:SecureSpodAccount/>' & @CRLF & _
            '<v16:Destination>' & @CRLF & _
            '<v16:GeographicCoordinates>rates evertitqueaequora</v16:GeographicCoordinates>' & @CRLF & _
            '</v16:Destination>' & @CRLF & _
            '</v16:SelectionDetails>' & @CRLF & _
            '</v16:TrackRequest>' & @CRLF & _
            '</soapenv:Body>' & @CRLF & _
            '</soapenv:Envelope>'

 

        $oHTTP = ObjCreate("Microsoft.XMLHTTP")
         $oHTTP.Open("POST", "https://ws.fedex.com:443/web-services", False)
         $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
         $oHTTP.Send($sPD)
         $oReceived = $oHTTP.ResponseText
         $oStatusCode = $oHTTP.Status
         If $oStatusCode <> 200 then
            MsgBox(4096, "Response code", $oStatusCode)
         EndIf
         $file = FileOpen("C:\track_received.xml", 2)
         FileWrite($file, $oReceived)
         FileClose($file)


         If _XMLFileOpen("C:\track_received.xml") Then
             Local $aRet = _XMLGetChildNodes('//*')
             If Not @error Then
                 For $i = 1 To $aRet[0]
                     ConsoleWrite($aRet[$i] & @LF)
                 Next
             EndIf
         EndIf

track_received.xml

Edited by NSearch
Posted

Today I'm tired. I just make a quick look ... your case is in progress.

 

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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Posted
On 12/17/2018 at 3:15 PM, mLipok said:

Today I'm tired. I just make a quick look ... your case is in progress.

 

Hi @mLipok,

I just wanted to make sure you were talking about the question I asked. I'm still researching solutions, but not having any luck. At one point there was a SOAPSDK3.0 Toolkit published by Microsoft, but that is no longer supported.

Thanks for your help.

Posted (edited)

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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Posted

Their solution was to access the node by relative XPath (i.e. tag="//xbe:ConversionRateResult"). Their response XML has xbe as the namespace, but my xml file I don't have namespaces to reference. Please see the track_received.xml file attached in the original post. Thank you

 

Posted (edited)
3 hours ago, NSearch said:

but my xml file I don't have namespaces to reference

 

Actually the track_received.xml file has 2 namespaces (xmlns) needed to access the node.  The following example shows one way that you can use xml.au3 functions to access that node.

image.png.810752d2c8aca0e468113ac4e64c9037.png

 

#include <xml.au3>  ;<-- Change to your location

example()

Func example()
    Const $XML_FILE  = "track_received.xml" ;<-- Point to your xml file

    Local $oXmlDocIn, $oNode

    ;Load XML file
    $oXmlDocIn = _XML_CreateDOMDocument()
    $oXmlDocIn = _XML_Load($oXmlDocIn, _
                           $XML_FILE, _
                           "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' " & _
                           "xmlns:a='http://fedex.com/ws/track/v16'" _
                           )
    ;Select node
    $oNode = _XML_SelectSingleNode($oXmlDocIn, '/SOAP-ENV:Envelope/SOAP-ENV:Body/a:TrackReply/a:CompletedTrackDetails/a:TrackDetails/a:Service/a:Type')

    ;Display text value
    ConsoleWrite(StringFormat("Type = %s", $oNode.text) & @CRLF)
EndFunc

 

Edited by TheXman
Posted
6 hours ago, TheXman said:

 

Actually the track_received.xml file has 2 namespaces (xmlns) needed to access the node.  The following example shows one way that you can use xml.au3 functions to access that node.

image.png.810752d2c8aca0e468113ac4e64c9037.png

 

#include <xml.au3>  ;<-- Change to your location

example()

Func example()
    Const $XML_FILE  = "track_received.xml" ;<-- Point to your xml file

    Local $oXmlDocIn, $oNode

    ;Load XML file
    $oXmlDocIn = _XML_CreateDOMDocument()
    $oXmlDocIn = _XML_Load($oXmlDocIn, _
                           $XML_FILE, _
                           "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' " & _
                           "xmlns:a='http://fedex.com/ws/track/v16'" _
                           )
    ;Select node
    $oNode = _XML_SelectSingleNode($oXmlDocIn, '/SOAP-ENV:Envelope/SOAP-ENV:Body/a:TrackReply/a:CompletedTrackDetails/a:TrackDetails/a:Service/a:Type')

    ;Display text value
    ConsoleWrite(StringFormat("Type = %s", $oNode.text) & @CRLF)
EndFunc

 

Thank you very much! What editor are you using to view the xml file? 

Posted (edited)

CLICK HERE
or here

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:

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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

  • 9 months later...
Posted

I have been having a bit of trouble the last couple of days with getChildNodes and just noticed now that I am also having the same problem using the supplied:

XML_1.1.1.13\XML__Examples.au3

 

Example 6 throws the following:

Quote

XML__Examples.au3 (274) : MainScript ==> COM Error intercepted !
    err.number is:         0x80020006
    err.windescription:    Unknown name.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     274
    err.retcode is:     0x00000000

When I use:

; change Nodes Collection to array
    Local $aNodesColl = _XML_Array_GetNodesProperties($oNodesColl)
    If @error Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'ERR:' & @error & ' EXT:' & @extended, XML_My_ErrorParser(@error, @extended))
    EndIf

from line 272 to give me an error I get this:

1.jpg.903489b08d58437826ddaa7e57cd9182.jpg

 

Am I doing something wrong? This is the same when I use my own XML or any other XML file.

 

Thanks

Posted (edited)

@Hiyoal

As it relates to the COM error in example 6, If I am looking at the same version as you are, then line 274 in the xml_example.au3 is:

_ArrayDisplay($aNodesColl, 'Example_6__XML_GetChildNodes: ' & 'Length=' & $oNodesColl.length & '   XPath=' & $oNodesColl.expr)

There appears to be a slight error in example 6.  In example 6, $oNodesColl is an IXMLDOMNodeList object.  IXMLDOMNodeList  objects do not have an "expr" property.  Therefore, if you just remove the reference to $oNodesColl.expr from line 274, you shouldn't get that COM error.  You can read more about the IXMLDOMNodeList object and its members HERE.

So just change line 274 to something like below and you will not get the COM error in example 6:

_ArrayDisplay($aNodesColl, 'Example_6__XML_GetChildNodes: ' & 'Length=' & $oNodesColl.length)

 

As for the 2nd error on line 272, I don't get that error when running example 6.  You would probably get a similar error if you moved the xml_examples.au3 file to a different location, without the supporting XML_Example_XML_Files folder structure, and tried to execute it.  That would be because it couldn't find the XML file that it needs.

Edited by TheXman
Posted (edited)

TheXman

Thanks for the first bit. I did try without both Length and Expr in testing but put it back to normal when writing up this post.

 

As for the other error, I haven't moved the XML_Example.au3 anywhere. Freshly unzipped with books.xml displaying its contents from the first msgbox.1.PNG.bcc5fa3baf760cc4b0e4bff531cea023.PNG

Func Example_6__XML_GetChildNodes()

    ; first you must create $oXmlDoc object
    Local $oXMLDoc = _XML_CreateDOMDocument(Default)

    ; Load file to $oXmlDoc
    Local $sXmlFile = @ScriptDir & "\XML_Example_XML_Files\MSDN\books.xml"
    _XML_Load($oXMLDoc, $sXmlFile)

    ; simple display $oXmlDoc - for checking only
    MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Example_6__XML_GetChildNodes', _XML_TIDY($oXMLDoc))

    ; selecting nodes
    Local $oNodesColl = _XML_GetChildNodes($oXMLDoc, "//book")

    ; change Nodes Collection to array
    Local $aNodesColl = _XML_Array_GetNodesProperties($oNodesColl)
    If @error Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'ERR:' & @error & ' EXT:' & @extended, XML_My_ErrorParser(@error, @extended))
    EndIf
    _ArrayDisplay($aNodesColl, 'Example_6__XML_GetChildNodes: ' & 'Length=' & $oNodesColl.length)

EndFunc    ;==>Example_6__XML_GetChildNodes

MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Example_6__XML_GetChildNodes', _XML_TIDY($oXMLDoc)) displays the contents of the XML loaded (books.xml), $oNodesColl gets returned as being successful in that it is an object, not null etc...and then _XML_Array_GetNodesProperties() throws that screenshot error I posted in my last post.

I tried downloading this on 2 other fresh PCs and I had the same result. I'm just stumped at this point...especially since you didn't get the error when running the script and its throwing the same error when I try and use _GetChildNodes() in my own script reading my own XML which I verified has loaded to $oXMLDoc 😮

Sorry about this :(

Edited by Hiyoal
Posted

If you are able to get the error over and over, can you try adding this slightly modified version of the example 6 function to the xml_examples.au3 file and executing it?  I named it Example_6A__XML_GetChildNodes().  It just has 3 additional ConsoleWrite lines that will give me a little more info about $oNodesColl.  Please post the result of the consolewrites.

 

Func Example_6A__XML_GetChildNodes()

    ; first you must create $oXmlDoc object
    Local $oXMLDoc = _XML_CreateDOMDocument(Default)

    ; Load file to $oXmlDoc
    Local $sXmlFile = @ScriptDir & "\XML_Example_XML_Files\MSDN\books.xml"
    _XML_Load($oXMLDoc, $sXmlFile)

    ; simple display $oXmlDoc - for checking only
    MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Example_6A__XML_GetChildNodes', _XML_TIDY($oXMLDoc))

    ; selecting nodes
    Local $oNodesColl = _XML_GetChildNodes($oXMLDoc, "//book")
    If @error Then Return SetError(@error, @extended)
    ConsoleWrite(StringFormat("$oNodesColl is a vartype of %s", VarGetType($oNodesColl)) & @CRLF)
    ConsoleWrite(StringFormat("$oNodesColl.length = %s", $oNodesColl.length) & @CRLF)
    ConsoleWrite(StringFormat("ObjName($oNodesColl) = %s", ObjName($oNodesColl, 1)) & @CRLF)

    ; change Nodes Collection to array
    Local $aNodesColl = _XML_Array_GetNodesProperties($oNodesColl)
    If @error Then Return SetError(@error, @extended)
    _ArrayDisplay($aNodesColl, 'Example_6__XML_GetChildNodes: ' & 'Length=' & $oNodesColl.length)

EndFunc    ;==>Example_6__XML_GetChildNodes

The ConsoleWrites should look like this.  Does yours look the same?

$oNodesColl is a vartype of Object
$oNodesColl.length = 6
ObjName($oNodesColl) = IXMLDOMNodeList

 

Posted (edited)

For sure.

My code I used (In case I missed something drastic 😮

Func Example_6__XML_GetChildNodes()

    ; first you must create $oXmlDoc object
    Local $oXMLDoc = _XML_CreateDOMDocument(Default)

    ; Load file to $oXmlDoc
    Local $sXmlFile = @ScriptDir & "\XML_Example_XML_Files\MSDN\books.xml"
    _XML_Load($oXMLDoc, $sXmlFile)

    ; simple display $oXmlDoc - for checking only
    MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'Example_6__XML_GetChildNodes', _XML_TIDY($oXMLDoc))

    ; selecting nodes
    Local $oNodesColl = _XML_GetChildNodes($oXMLDoc, "//book")
    If @error Then Return SetError(@error, @extended)
    ConsoleWrite(StringFormat("$oNodesColl is a vartype of %s", VarGetType($oNodesColl)) & @CRLF)
    ConsoleWrite(StringFormat("$oNodesColl.length = %s", $oNodesColl.length) & @CRLF)
    ConsoleWrite(StringFormat("ObjName($oNodesColl) = %s", ObjName($oNodesColl, 1)) & @CRLF)

    ; change Nodes Collection to array
    Local $aNodesColl = _XML_Array_GetNodesProperties($oNodesColl)
    If @error Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, 'ERR:' & @error & ' EXT:' & @extended, XML_My_ErrorParser(@error, @extended))
    EndIf
    _ArrayDisplay($aNodesColl, 'Example_6__XML_GetChildNodes: ' & 'Length=' & $oNodesColl.length)

EndFunc    ;==>Example_6__XML_GetChildNodes

Console Output:

$oNodesColl is a vartype of Object
$oNodesColl.length = 13
ObjName($oNodesColl) = IXMLDOMNodeList

 

Different length than yours but the object is of the same type??

I am still getting that screenshot error too (I know consolewrite's wouldn't be fixing that and it was for debug purposes):

1.jpg.327fc1d72ba15cd37b6a2df1d248ff42.jpg

Edited by Hiyoal

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
×
×
  • Create New...