XPATH and clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lucalla
    New Member
    • Feb 2008
    • 1

    XPATH and clause

    Sorry if this has been answered, I had a hard time search for 'and'.

    I have an XML document (snippet below) and I am trying to retrieve the FREIGHTFEE's attributes based on the value of multiple elements, as follows. Actually, for now I'm just trying to locate the elements that meet my criteria:

    varCompany = 01 AND
    varCustomer = *ALL AND
    varShip = STD AND
    varSTATE= IL

    I have tried:
    doc.Query("/FREIGHT_XREF/COMPANIES[COMPANY=varComa pny]/COMPANY[CUSTOMER=varCus tomer]/CUSTOMER[VS_SHIP=varShip]/COUNTRY[STATE=varState]")
    and various permutations thereof, with no success. Where am I going wrong?

    <FREIGHT_XREF >
    <COMPANIES>
    <COMPANY>
    01
    <CUSTOMER>
    *ALL
    <VS_SHIP>
    STD
    <COUNTRY>
    USA
    <STATE>
    *ALL
    <FREIGHTFEE UPSCode="UPN" TOD="PPA" Value="12.00" />
    </STATE>
    <STATE>
    IL
    <FREIGHTFEE UPSCode="UGC" TOD="PPA" Value="4.00" />
    </STATE>
    <STATE>
    HI
    <FREIGHTFEE UPSCode="UP2" TOD="PPA" Value="10.00" />
    </STATE>
    </COUNTRY>
    </VS_SHIP>
    </CUSTOMER>
    </COMPANY>
    </COMPANIES>
    </FREIGHT_XREF>
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Change 1: Are you treating the variables properly as strings?

    doc.Query("/FREIGHT_XREF/COMPANIES[COMPANY=" + varCompany + "]/COMPANY[CUSTOMER=" + varCustomer + "]/CUSTOMER[VS_SHIP=" + varShip + "]/COUNTRY[STATE=" + varState+"]")

    Change 2: Make sure you're actually going to the right nodes:

    doc.Query("/FREIGHT_XREF/COMPANIES/COMPANY[text() ="+ varCompany+"]/CUSTOMER[text() =" + varCustomer + "]/VS_SHIP[text() =" + varShip + "]/COUNTRY[STATE=" + varState+"]")

    Comment

    Working...