Jump to content

_XMLGetAttrib - I'm clueless


Recommended Posts

Well tax season is almost over (in Canada deadline June15 for self-employed and their spouses) so I’m devoting more time to Autoit but am hitting a brick wall and will explain on another post soon. Today’s problem is minor (for you that is) and involves _XMLGetAttrib syntax, I think. There is not much out there, so I followed this snippet.

As you can see, everything works great until the loop which returns blanks because I really have no idea what I am doing with XML. I can extract required information using alternate means but it would be much simpler if I could figure out _XMLGetAttrib.

Please help.

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

Global $sXML_File = "C:\Temp6.XML"
Global $aRET, $iRET, $sRET

$iRET = _XMLFileOpen($sXML_File)
ConsoleWrite("Open:          $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$iRET = _XMLGetNodeCount("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet")
ConsoleWrite("Group(s):      $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$iRET = _XMLGetNodeCount("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet")
ConsoleWrite("Subgroup(s):   $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

For $n = 1 to $iRET
    $sRET = _XMLGetAttrib("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet[" & $n & "]", "Name")
    ConsoleWrite("Name[" & $n & "]:  " & $sRET & @LF)
Next

XML is attached

Edit - I remembered the you don't like "I'm clueless" in titles and would like to change it and can someone please direct me how to change the title. Please?

Temp6.XML

Edited by 1905russell
Link to comment
Share on other sites

Your first problem is that "Name" is an element with a VALUE, not an attribute:

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

Global $sXML_File = @ScriptDir & "\Temp6.XML"
Global $aRET, $iRET, $sRET

$iRET = _XMLFileOpen($sXML_File)
ConsoleWrite("Open:          $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$iRET = _XMLGetNodeCount("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet")
ConsoleWrite("Group(s):      $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

; All at once:
$aRET = _XMLGetValue("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet/Name")
_ArrayDisplay($aRET, "$aRet")

; One at a time:
For $n = 1 To $iRET
    $aRET = _XMLGetValue("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet[" & $n & "]/Name")
    _ArrayDisplay($aRET, $n & ":  $aRet")
Next

Now suppose, for purposes of (our mutual) instruction, that the "SalesTaxCountry" elements had "language" tags:

<?xml version="1.0" ?>
<QBXML>
    <QBXMLMsgsRs>
        <CustomerQueryRs requestID="0" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
            <CustomerRet>
                <ListID>80000007-1273620121</ListID>
                <TimeCreated>2010-05-11T19:22:01-05:00</TimeCreated>
                <TimeModified>2010-05-11T19:22:01-05:00</TimeModified>
                <EditSequence>1273620121</EditSequence>
                <Name>A Company</Name>
                <FullName>A Company</FullName>
                <IsActive>true</IsActive>
                <Sublevel>0</Sublevel>
                <Balance>0.00</Balance>
                <TotalBalance>0.00</TotalBalance>
                <SalesTaxCountry language="English">Canada</SalesTaxCountry>
                <JobStatus>None</JobStatus>
            </CustomerRet>
            <CustomerRet>
                <ListID>80000008-1273620131</ListID>
                <TimeCreated>2010-05-11T19:22:11-05:00</TimeCreated>
                <TimeModified>2010-05-11T19:22:11-05:00</TimeModified>
                <EditSequence>1273620131</EditSequence>
                <Name>B Company</Name>
                <FullName>B Company</FullName>
                <IsActive>true</IsActive>
                <Sublevel>0</Sublevel>
                <Balance>0.00</Balance>
                <TotalBalance>0.00</TotalBalance>
                <SalesTaxCountry language="Spanish">Spain</SalesTaxCountry>
                <JobStatus>None</JobStatus>
            </CustomerRet>
            <CustomerRet>
                <ListID>8000000F-1274363313</ListID>
                <TimeCreated>2010-05-20T09:48:33-05:00</TimeCreated>
                <TimeModified>2010-05-20T09:48:33-05:00</TimeModified>
                <EditSequence>1274363313</EditSequence>
                <Name>C Company</Name>
                <FullName>C Company</FullName>
                <IsActive>true</IsActive>
                <Sublevel>0</Sublevel>
                <Balance>0.00</Balance>
                <TotalBalance>0.00</TotalBalance>
                <SalesTaxCountry language="Arabic">Bahrain</SalesTaxCountry>
                <JobStatus>None</JobStatus>
            </CustomerRet>
        </CustomerQueryRs>
    </QBXMLMsgsRs>
</QBXML>

Then you might run this:

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

Global $sXML_File = @ScriptDir & "\Temp6.XML"
Global $aRET, $iRET, $sRET

$iRET = _XMLFileOpen($sXML_File)
ConsoleWrite("Open:          $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$iRET = _XMLGetNodeCount("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet")
ConsoleWrite("Group(s):      $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$aNames = _XMLGetValue("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet/Name")
$aTaxCountries = _XMLGetValue("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet/SalesTaxCountry")
Global $aData[$iRET + 1][3] = [[$iRET, "", ""]]
For $n = 1 To $iRET
    $sLanguage = _XMLGetAttrib("/QBXML/QBXMLMsgsRs/CustomerQueryRs/CustomerRet[" & $n & "]/SalesTaxCountry", "language")
    $aData[$n][0] = $aNames[$n]
    $aData[$n][1] = $aTaxCountries[$n]
    $aData[$n][2] = $sLanguage
Next

_ArrayDisplay($aData, "$aData")

:idea:

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

Wonderful stuff - thank you for pointing out my first problem, also, thanks for not revealing my second one.

These multi-aspect examples provide a great Autoit education. Incredible power in a couple of lines.

I find XMLDOMWrapper extremely intimidating. I’m an accountant - xml is all foreign to me. However, I will never confuse attributes with values again – well maybe not never. Hopefully others like me are now only partially xml clueless and we don’t have to fear it as much, thanks again to you o’ marvelous venerable one.

Link to comment
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
 Share

  • Recently Browsing   0 members

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