Sign in to follow this  
Followers 0
ChrisL

XML Dom Wrapper help

8 posts in this topic

I'm a bit confused I have an XML file

<?xml version="1.0"?>
<Frontier>
    <Machine>
    
        <ProductName>FRONTIER MP Controller</ProductName>
        <Version>2.1-0E-010</Version>
        <PrinterVersion>2.5-0X-120k</PrinterVersion>
        
    </Machine>
    
    <ProductionLog>
    
        <PrintSize> 
            <Name>102 x 152</Name>
            <Qty>0</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>127 x 178</Name>
            <Qty>0</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>152 x 102</Name>
            <Qty>0</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>6x4</Name>
            <Qty>310</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>6x4</Name>

        </PrintSize>
        <PrintSize> 
            <Name>5x7</Name>
            <Qty>183</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>6x8</Name>
            <Qty>7</Qty>
        </PrintSize>
        <PrintSize> 
            <Name>6x9</Name>
            <Qty>82</Qty>
        </PrintSize>
        
    </ProductionLog>

</Frontier>

But I'm not understanding exactly how to retrieve the data out of the file.

This is what I have so far but you will notice that 6x4 doesn't have a <qty> so I can't reliable match arrays $a and $b up.

So can someone show me how your supposed to use the DOM Wrapper to get the data please.

#include "_XMLDomWrapper.au3"
#include <Array.au3>

$debugging = 1

$ret = _XMLFileOpen ("ProdLog.xml")

$Machine = _GetFirstValue("/Frontier/Machine/ProductName")
$Version = _GetFirstValue("/Frontier/Machine/Version")
$PVersion = _GetFirstValue("/Frontier/Machine/PrinterVersion")
Msgbox(0,"This bit is fine",$Machine & @CRLF & $Version & @CRLF & $PVersion)



$a = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Name") 
$b = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Qty") 
_ArrayDisplay($a)
_ArrayDisplay($b)


;Get the first real value returned from the _XMLGetValue() return array.
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) and Ubound($ret_val) > 1 Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc

I'm using eltorro's XML Wrapper

Share this post


Link to post
Share on other sites



@ChrisL...Maybe there is a different way but this is how I would do it... :P

Dim $Final[1]

$iNodeCt = _XMLGetNodeCount ("/Frontier/ProductionLog/*")
;MsgBox(4096,"",$iNodeCt)

For $x=1 to $iNodeCt

$iNodeCt2=_XMLGetNodeCount("/Frontier/ProductionLog/PrintSize[" & $x & "]/*")
;MsgBox(4096,"",$iNodeCt2)
    
    $y = _XMLGetChildNodes("/Frontier/ProductionLog/PrintSize[" & $x & "]")
;MsgBox(4096,"","/Frontier/ProductionLog/PrintSize[" & $x & "]")
;_ArrayDisplay($y)
    
    For $z=1 to $y[0]
        
        $b=_XMLGetValue("/Frontier/ProductionLog/PrintSize[" & $x & "]/" & $y[$z])
    ;_ArrayDisplay($b)
        
    ;MsgBox(4096,$iNodeCt2,"PrintSize[" & $x & "]=" & $y[$z] & "=" & $b[1])
        _ArrayAdd($Final,"PrintSize[" & $x & "]=" & $y[$z] & "=" & $b[1])
        
    Next

Next

_ArrayDisplay($Final,"")

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The original code wasn't bad. I don't really understand what you meant by "couldn't match arrays up".

I would have changed this.

$a = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Name") 
 $b = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Qty") 
 _ArrayDisplay($a)
 _ArrayDisplay($b)

To this.

$a = _XMLGetFirstValue("/Frontier/ProductionLog/PrintSize/Name") 
 $b = _XMLGetFirstValue("/Frontier/ProductionLog/PrintSize/Qty")

Then just check if $b is empty or check for @ERROR.

Edited by weaponx

Share this post


Link to post
Share on other sites

The original code wasn't bad. I don't really understand what you meant by "couldn't match arrays up".

I would have changed this.

$a = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Name") 
 $b = _XMLGetValue("/Frontier/ProductionLog/PrintSize/Qty") 
 _ArrayDisplay($a)
 _ArrayDisplay($b)

To this.

$a = _XMLGetFirstValue("/Frontier/ProductionLog/PrintSize/Name") 
 $b = _XMLGetFirstValue("/Frontier/ProductionLog/PrintSize/Qty")

Then just check if $b is empty or check for @ERROR.

It was because I was getting an array of all values in a single go so $a had 8 entries and $b had 7, I hadn't figured out how to run through them 1 PrintSize Node at a time.

I keep reading how this XML simplifies things but so far it hasn't simplified any thing for me :P

Share this post


Link to post
Share on other sites

I think it doesn't seem simple because of the wrapper itself having to take something object oriented, and making NOT object oriented. If you use ObjCreate to create an "Msxml2.DOMDocument" instance, you might be more comfortable.

I personally prefer using XML in Actionscript.

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