Sign in to follow this  
Followers 0
WSorich

Extracting information using XMLDomWrapper

4 posts in this topic

Hi, thanks for stopping by. I have the following XML document and am trying to discover how I can extract the names of the fields as held in the value="" attributes.

- <results>
  - <metadata>
    - <fields>
        <name value="IMPORTID" alias="IMPORTID" type="7" size="4" scale="0" /> 
        <name value="MODELID" alias="MODELID" type="7" size="4" scale="0" /> 
        <name value="DATE" alias="DATE" type="2" size="4" scale="0" /> 
        <name value="FILECRC" alias="FILECRC" type="7" size="4" scale="0" /> 
        <name value="URL" alias="URL" type="5" size="200" scale="0" /> 
        <name value="IMPORTDATE" alias="IMPORTDATE" type="2" size="4" scale="0" /> 
        <name value="RC_STAMP" alias="RC_STAMP" type="4" size="8" scale="0" /> 
        <name value="HO_STAMP" alias="HO_STAMP" type="4" size="8" scale="0" /> 
        <name value="YN" alias="YN" type="5" size="1" scale="0" /> 
       </fields>
     </metadata>
  - <data>
    - <row num="1">
        <IMPORTID>1</IMPORTID> 
        <MODELID>1</MODELID> 
        <DATE>2000-01-01</DATE> 
        <FILECRC>12345678</FILECRC> 
      - <URL>
          <![CDATA[  ]]> 
        </URI>
      <IMPORTDATE>1900-00-00</IMPORTDATE> 
      <RC_STAMP>2006-05-29 20:59:40</RC_STAMP> 
      <HO_STAMP>2008-05-17 16:08:47</HO_STAMP> 
      - <YN>
          <![CDATA[  ]]> 
        </YN>
    </row>
  </data>
</results>

I have the following which runs, but it seems to only return the last attribute "YN"

$ReturnedNodeValue =_XMLGetAllAttrib("/results/metadata/fields/name",$aAttrName,$aAttrValue);
_ArrayDisplay($ReturnedNodeValue," $ReturnedNodeValue ")
_ArrayDisplay($aAttrName," $aAttrName ")
_ArrayDisplay($aAttrValue," $aAttrValue ")

The output looks like this

$ReturnedNodeValue
[Row]  [Col 0]  [Col 1]  [Col 2]  [Col 3]  [Col 4]  [Col 5]  [Col 6]
[0]    [5]      [value]  [alias]  [type]   [size]   [scale]  []
[1]    []       [YN]     [YN]     [5]      [1]      [0]      []

$aAttrName
[Row]  [Col 0]
[0]    [value]
[1]    [alias]
[2]    [type]
[3]    [size]
[4]    [scale]

aAttrValue
[Row]  [Col 0]
[0]    [YN]
[1]    [YN]
[2]    [5]
[3]    [1]
[4]    [0]

So it looks as though it is only getting the last entry and I really need to get all of the entries.

Any suggestions?

Thanks in advance for taking the time to look at my problem here.

Share this post


Link to post
Share on other sites



You could do something like this

$iCount = _XMLGetNodeCount("/results/metadata/fields/name")


Local $aAttrName,$aAttrValue

For $i = 1 to $iCount

    $ReturnedNodeValue =_XMLGetAllAttrib("/results/metadata/fields/name[" & $i & "]",$aAttrName,$aAttrValue);
    _ArrayDisplay($ReturnedNodeValue," $ReturnedNodeValue ")
    _ArrayDisplay($aAttrName," $aAttrName ")
    _ArrayDisplay($aAttrValue," $aAttrValue ")

Next

Share this post


Link to post
Share on other sites

You may find this helpful,

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

; Open file
$sXML = @ScriptDir & "\Test.xml"
If _XMLFileOpen($sXML,"",-1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

; Get count of item nodes in menu
$iItems = _XMLGetNodeCount("/results/metadata/fields/name")

Local $cAttribs
Local $aAttrName[1]
Local $aAttrValue[1]
$ReturnedNodeValue =_XMLGetAllAttrib("/results/metadata/fields/name",$aAttrName,$aAttrValue);

; List the "name" attribute of each item
For $i = 1 To $iItems -1
    $attrib1 = _XMLGetAttrib("/results/metadata/fields/name[" & $i & "]","value")
    $attrib2 = _XMLGetAttrib("/results/metadata/fields/name[" & $i & "]","alias")
    $attrib3 = _XMLGetAttrib("/results/metadata/fields/name[" & $i & "]","type")
    $attrib4 = _XMLGetAttrib("/results/metadata/fields/name[" & $i & "]","size")
    $attrib5 = _XMLGetAttrib("/results/metadata/fields/name[" & $i & "]","scale")
    
    $Attribs = $attrib1 & "," & $attrib2 & "," & $attrib3 & "," & $attrib4 & "," & $attrib5 ;& ";"
    $cAttribs = $cAttribs & $Attribs        
Next
$splitAttribs1 = StringSplit($cAttribs, ",")

_ArrayDisplay($splitAttribs1, "Title ")

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites

Thanks ChrisL your code showed me exactly how to address the multiple items that I needed. Your assistance is greatly appreciated. I think I can work through the other issues I am having now.

Thanks jfcby for expanding on the the example and adding the surrounding code. This will allow me to look at the problem from another angle and see how to utilise the XMLDomWrapper calls better.

Much appreciated. Wal.

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
Sign in to follow this  
Followers 0