Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_XMLGetAttrib - I'm clueless


  • Please log in to reply
2 replies to this topic

#1 1905russell

1905russell

    Prodigy

  • Active Members
  • PipPipPip
  • 162 posts

Posted 20 May 2010 - 02:47 PM

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?

Attached Files


Edited by 1905russell, 20 May 2010 - 04:01 PM.








#2 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 20 May 2010 - 07:22 PM

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:
Plain Text         
<?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:
Plain Text         
#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, 20 May 2010 - 07:23 PM.

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

#3 1905russell

1905russell

    Prodigy

  • Active Members
  • PipPipPip
  • 162 posts

Posted 21 May 2010 - 06:35 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users