Hey I think I got it. Looks like I need to prefix *everything* with the
Looks like it's a combination of both your great info. Thanks guys!
"Michael C#" <xyz@abcdef.com> wrote in message
news:UpjHd.4547$uA3.3097@fe08.lga...
> Oops, that's VB.NET. Here's the C#.NET version:
>
> System.Xml.XmlDocument XDoc = New System.Xml.XmlDocument();
> string XPathQuery = "//tblItem[Category='Miscellaneous']";
> XDoc.Load(Server.MapPath("StoreItems.xml"));
> System.Xml.XmlNodeList XMLResults = XDoc.SelectNodes(XPathQuery);
>
> Thanks
>
> "Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in message
> news:6fSdnVkJiuJhrXDcRVn-vQ@comcast.com...
>> try these:
>>
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconManageNamespacesUsingXmlNamespaceManager.asp >>
http://msdn.microsoft.com/library/en-us/dnxmlnet/html/xpthviewer.asp >>
>> --
>> --- Nick Malik [Microsoft]
>> MCSD, CFPS, Certified Scrummaster
>>
http://blogs.msdn.com/nickmalik >>
>> Disclaimer: Opinions expressed in this forum are my own, and not
>> representative of my employer.
>> I do not answer questions on behalf of my employer. I'm just a
>> programmer helping programmers.
>> --
>> "Michael C" <me@mine.com> wrote in message
>> news:ucaxASX$EHA.1904@TK2MSFTNGP14.phx.gbl...
>>> Now that sounds like it hit the nail on the head. Where can I find out
>> more
>>> about the namespace manager?
>>>
>>> Thanks
>>>
>>> "Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in message
>>> news:cNqdnbEFPI0eM3HcRVn-hg@comcast.com...
>>> > one more thing: a good link with a tutorial on XPath queries is:
>>> >
http://www.w3schools.com/xpath/xpath_syntax.asp >>> >
>>> > --
>>> > --- Nick Malik [Microsoft]
>>> > MCSD, CFPS, Certified Scrummaster
>>> >
http://blogs.msdn.com/nickmalik >>> >
>>> > Disclaimer: Opinions expressed in this forum are my own, and not
>>> > representative of my employer.
>>> > I do not answer questions on behalf of my employer. I'm just a
>>> > programmer helping programmers.
>>> > --
>>> > "Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in
>>> > message
>>> > news:GbudnZ009YuRM3HcRVn-uA@comcast.com...
>>> > > your first two queries are not difficult:
>>> > >
>>> > > > 1) All tblItem nodes that have a child ID node with a value of 1
>>> (i.e.,
>>> > > all
>>> > > > tblItem where ID = 1),
>>> > >
>>> > > //tblItem[ID=1]
>>> > >
>>> > > > 2) All tblItem nodes that have a Category of Miscellaneous (i.e.,
>> all
>>> > > > tblItem where Category = 'Miscellaneous')
>>> > >
>>> > > //tblItem[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)
>>> > > >
>>> > > I don't know this one.
>>> > >
>>> > >
>>> > > One thing that you have to keep in mind, if you want to do this in
>> code,
>>> > is
>>> > > that you have to set the namespace manager for the xpath query to
>>> include
>>> > > the defined namespaces. In your example, you have a default
>> namespace.
>>> > If
>>> > > you don't provide the namespace manager, then your query will ALWAYS
>>> > return
>>> > > zero results.
>>> > >
>>> > > --
>>> > > --- Nick Malik [Microsoft]
>>> > > MCSD, CFPS, Certified Scrummaster
>>> > >
http://blogs.msdn.com/nickmalik >>> > >
>>> > > Disclaimer: Opinions expressed in this forum are my own, and not
>>> > > representative of my employer.
>>> > > I do not answer questions on behalf of my employer. I'm just a
>>> > > programmer helping programmers.
>>> > > --
>>> > > "Michael C#" <xyz@abcdef.com> wrote in message
>>> > > news:650Hd.4453$rs5.3793@fe08.lga...
>>> > > > 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
>>> > > >
>>> > > >
>>> > > >
>>> > >
>>> > >
>>> >
>>> >
>>>
>>>
>>
>>
>
>