Having a hell using XPATH to parse out the values from the XML below. Wondering if anyone can tell me what I'm doing wrong.

<?xml version="1.0" encoding="UTF-8"?>
<XML>
    <VARIABLES>
        <var name="LoginUUID" value="F85373F9-00C4-7982-E043-AB7412ACA458"/>
        <var name="FExists" value="0"/>
        <var name="NumFTokens" value="0"/>
        <var name="NumPTokens" value="9"/>

                    <var name="purchaseOptions_Poductname1" value="500 MB"/>
                    <var name="purchaseOptions_Poductvalue1" value="7"/>
                    <var name="purchaseOptions_Poductpricevalue1" value="5"/>

                    <var name="purchaseOptions_Poductname2" value="1 GB"/>
                    <var name="purchaseOptions_Poductvalue2" value="8"/>
                    <var name="purchaseOptions_Poductpricevalue2" value="9"/>

                    <var name="purchaseOptions_Poductname3" value="2 GB"/>
                    <var name="purchaseOptions_Poductvalue3" value="9"/>
                    <var name="purchaseOptions_Poductpricevalue3" value="16"/>

                    <var name="purchaseOptions_Poductname5" value="Token - Prepaid"/>
                    <var name="purchaseOptions_Poductvalue5" value="6"/>
                    <var name="purchaseOptions_Poductpricevalue5" value="0"/>

    </VARIABLES>
</XML> 

Best I have been able to come up with is:

//XML/VARIABLES/var[3]

Which gets me:

<var name="NumFTokens" value="0" />

But what I really need to do is search for @NumFTokens, and get the resulting value (i.e "0") and I can't figure out how to do it.

This has me completely stumped at the moment

tag name never use with xml
injury of the xml rule

use [] as an if statement

var[@name='NumFTokens']

so you can search for the name and then get the value
sample

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <VARIABLES>
        <var name="LoginUUID" value="F85373F9-00C4-7982-E043-AB7412ACA458"/>
        <var name="FExists" value="0"/>
        <var name="NumFTokens" value="0"/>
        <var name="NumPTokens" value="9"/>
        <var name="purchaseOptions_Poductname1" value="500 MB"/>
        <var name="purchaseOptions_Poductvalue1" value="7"/>
        <var name="purchaseOptions_Poductpricevalue1" value="5"/>
        <var name="purchaseOptions_Poductname2" value="1 GB"/>
        <var name="purchaseOptions_Poductvalue2" value="8"/>
        <var name="purchaseOptions_Poductpricevalue2" value="9"/>
        <var name="purchaseOptions_Poductname3" value="2 GB"/>
        <var name="purchaseOptions_Poductvalue3" value="9"/>
        <var name="purchaseOptions_Poductpricevalue3" value="16"/>
        <var name="purchaseOptions_Poductname5" value="Token - Prepaid"/>
        <var name="purchaseOptions_Poductvalue5" value="6"/>
        <var name="purchaseOptions_Poductpricevalue5" value="0"/>
    </VARIABLES>
</ROOT>

xpath

//ROOT/VARIABLES/var[@name='NumFTokens']/@value

result
0

This article has been dead for over six months. Start a new discussion instead.