Search code examples
asp.netxmlreadxml

XML Read specific Node


I want to read an specific xml node and its value for example

<customers>
<name>John</name>
<lastname>fetcher</lastname>
</customer>

and my code behind should be some thing like this (I don't know how it should be though):

Response.Write(xml.Node["name"].Value) 

As I said it is just an example because I don't know how to do it.


Solution

  • The most basic answer:
    Assuming "xml" is an XMLDocument, XMLNodeList, XMLNode, etc...

    Response.Write(xml.SelectSingleNode("//name").innerText)