What is 开发者_运维知识库the best way to get node value by using XPath API in C#?
<employee nric="S100" name="Mike" ... />
In T-SQL, the following will give the result:
select xml.value('(/employee/@nric)[1]','nvarchar(max)')
Using an XmlDocument
:
string s = "<employee nric=\"S100\" name=\"Mike\" />";
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
string value = doc.SelectSingleNode("//employee/@nric").Value;
Select Nodes Using XPath Navigation will be a good start. Then Xpath and selecting a single node
精彩评论