XPath

T

Tony Johansson

Hello!

How do I write an XPath query to find all node that don't have NA in the
Discount tag ?


?xml version="1.0" standalone="yes"?>
<Products>
<Product ID="1">
<FlightName>Stholm-Oslo ToR</FlightName>
<Category>BusinesClass</Category>
<Price>9000</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
<Product ID="2">
<FlightName>Stholm-Oslo ToR</FlightName>
<Category>SecondClass</Category>
<Price>5400</Price>
<Discount>10</Discount>
<Area>Norden</Area>
</Product>

<Product ID="5">
<FlightName>Stholm-Helsingfors ToR</FlightName>
<Category>BusinesClass</Category>
<Price>8888</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
<Product ID="7">
<FlightName>Stholm-Rejkavik ToR</FlightName>
<Category>BusinesClass</Category>
<Price>9000</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
</Products>

//Tony
 
B

bradbury9

El domingo, 10 de junio de 2012 19:49:50 UTC+2, Tony Johansson escribió:
Hello!

How do I write an XPath query to find all node that don't have NA in the
Discount tag ?


?xml version="1.0" standalone="yes"?>
<Products>
<Product ID="1">
<FlightName>Stholm-Oslo ToR</FlightName>
<Category>BusinesClass</Category>
<Price>9000</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
<Product ID="2">
<FlightName>Stholm-Oslo ToR</FlightName>
<Category>SecondClass</Category>
<Price>5400</Price>
<Discount>10</Discount>
<Area>Norden</Area>
</Product>

<Product ID="5">
<FlightName>Stholm-Helsingfors ToR</FlightName>
<Category>BusinesClass</Category>
<Price>8888</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
<Product ID="7">
<FlightName>Stholm-Rejkavik ToR</FlightName>
<Category>BusinesClass</Category>
<Price>9000</Price>
<Discount>NA</Discount>
<Area>Norden</Area>
</Product>
</Products>

//Tony

Maybe I am wrong. I am ot good at XML, but if the value is not set as an attribute you cannot filter it with xpath. When I try to make complex xpath icheck this page http://www.w3schools.com/xpath/xpath_syntax.asp which I find very usefull.

Anyway that is not a c# related question, maybe asking in anothe forum would give you a better answer.

I would use Linq Where function to check for the XmlNode inner text if i amright and you cannot use xpath.
 
B

bradbury9

El lunes, 11 de junio de 2012 09:33:40 UTC+2, bradbury9 escribió:
El domingo, 10 de junio de 2012 19:49:50 UTC+2, Tony Johansson escribió:

Maybe I am wrong. I am ot good at XML, but if the value is not set as an attribute you cannot filter it with xpath. When I try to make complex xpathi check this page http://www.w3schools.com/xpath/xpath_syntax.asp which I find very usefull.

Anyway that is not a c# related question, maybe asking in anothe forum would give you a better answer.

I would use Linq Where function to check for the XmlNode inner text if i am right and you cannot use xpath.


I was wrong, from the linq i gave u before:

Products/Product[Discount!='NA']
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top