XPath Query

Discussion in 'ASP .Net' started by Michael C#, Jan 18, 2005.

  1. Michael C#

    Michael C# Guest

    OK, here's the deal. I have a small XML file that represents a small
    database table. I load it into a System.XML.XMLDocument. So far so good.
    I run an XPath query against it to retrieve all the field names. Everything
    there works fine.

    Here's my XML Document:

    <?xml version="1.0" standalone="yes" ?>
    <DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd">
    <tblItem>
    <ID>1</ID>
    <Name>Spam</Name>
    <Category>Food</Category>
    <Description>Yummy! No natural ingredients</Description>
    <Price>4</Price>
    <ImageURL>images/1.png</ImageURL>
    <LargeImageURL>images/L1.png</LargeImageURL>
    </tblItem>
    <tblItem>
    <ID>2</ID>
    <Name>Remote Control</Name>
    <Category>Miscellaneous</Category>
    <Description>Universal Remote</Description>
    <Price>12</Price>
    <ImageURL>images/2.png</ImageURL>
    <LargeImageURL>images/L2.png</LargeImageURL>
    </tblItem>
    </DataSet>

    Now for the tricky part. I'm trying to come up with three XPath queries
    that will return the following:

    1) All tblItem nodes that have a child ID node with a value of 1 (i.e., all
    tblItem where ID = 1),
    2) All tblItem nodes that have a Category of Miscellaneous (i.e., all
    tblItem where Category = 'Miscellaneous')
    3) All tblItem ndoes that have the word Remote in the Description (i.e., all
    tblItem where Category contains the word 'Remote' in any position)

    Coming from a SQL background, I'm having a hard time implementing XPath
    expressions. I was hoping someone here could point me in the right
    direction. I've tried several combinations, like "tblItem/ID[.='1']",
    "tblItem[ID='1']" and "//tblItem[ID='Miscellaneous']". None of them seem to
    be working though...

    TIA
     
    Michael C#, Jan 18, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,974
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,414
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    523
  4. goog
    Replies:
    0
    Views:
    508
  5. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    793
    David Gordon
    May 18, 2005
Loading...

Share This Page