-3

I have a xml file look like

<info>

  <Data Name="ProcessName">-</Data> 
  <Data Name="IpAddress">10.1.2.118</Data> 
  <Data Name="IpPort">50118</Data> 
  <Data Name="ProcessName">-</Data> 
  <Data Name="IpAddress">10.1.2.119</Data> 
  <Data Name="IpPort">50118</Data> 
  <Data Name="ProcessName">-</Data> 
  <Data Name="IpAddress">10.1.2.120</Data> 
  <Data Name="IpPort">50118</Data> 
  <Data Name="ProcessName">-</Data> 
  <Data Name="IpAddress">10.1.2.157</Data> 
  <Data Name="IpPort">50118</Data> 


</info>

i need extract the data node with name attribute value ="Ipaddress" and Node value =10.1.2.157, how i can use this using any xml querying techniques

Binson Eldhose
  • 993
  • 3
  • 14
  • 35
  • 2
    What have you tried? And you say XPath then say 'any xml querying techniques' - so do you want XPath for a reason or is that choice entirely arbitrary? What do you want to do with the node once extracted (given your query knows all the data relating to it!)? – Charles Mager May 20 '15 at 09:02
  • @charles mager , lets say i need a string from this xml file whose attribute value 'IpAddress' and node value=10.1.2.157 – Binson Eldhose May 20 '15 at 09:15
  • 1
    'Lets say'? What string? It's not clear what you're asking or what your end result is, and it looks like you've put no effort into solving this yourself first. Read [How to ask](http://stackoverflow.com/help/how-to-ask). – Charles Mager May 20 '15 at 09:22
  • @Charles mager, just check how got the answer from Matt Jones.. he clearly understood what the question and what required. thanks – Binson Eldhose May 20 '15 at 09:26
  • The answer involves making assumptions and has nothing to do with `c#` or `.net` which is how you've tagged your question. Just because you got what you wanted doesn't mean the question is clear. – Charles Mager May 20 '15 at 09:30
  • possible duplicate of [Using XPath, How do I select a node based on its text content and value of an attribute?](http://stackoverflow.com/questions/1982624/using-xpath-how-do-i-select-a-node-based-on-its-text-content-and-value-of-an-at) – dirkk May 20 '15 at 12:55

1 Answers1

1

If that XML is your entire document, then the following XPath should select the Data element that you require:

./info/Data[@Name='IpAddress'][.='10.1.2.157']

The ./info/Data will match child nodes of info that are named Data and the [@Name='IpAddress'][.='10.1.2.157'] contains two predicates - one to match the Name attribute to have a value of "IpAddress" and the other to match the element's content as you have specified.

Matt Hogan-Jones
  • 2,981
  • 1
  • 29
  • 35