开发者

What is the best way to get node value by using XPath API in C#?

开发者 https://www.devze.com 2023-02-02 04:02 出处:网络
What is 开发者_运维知识库the best way to get node value by using XPath API in C#? <employee nric=\"S100\" name=\"Mike\" ... />

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

0

精彩评论

暂无评论...
验证码 换一张
取 消