从 xml 文档中读取内部文本
本文关键字:内部 文本 读取 xml 文档 | 更新日期: 2023-09-27 18:34:19
如何使用
SelectSingleNode 获取 OverallResult 元素的内部文本?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ProcessResp xmlns="http://www.w3.org/2005/Atom">
<Result>
<OverallResult>Success</OverallResult>
var doc = new XmlDocument();
doc.LoadXml(xml);
var text = doc.SelectSingleNode("Example/Node/text()").InnerText; // or .Value
返回
"Some text here'r'n "
和文本。Trim() 返回
"Some text here"
请通过以下链接进行XML相关查询,这对乞丐非常有用!
http://www.dotnetcurry.com/ShowArticle.aspx?ID=564
对于您的答案(我没有尝试过,尽管尝试通过在您的代码中像这样更改来尝试)
doc.SelectSingleNode("soap/ProcessResp/ Result/OverallResult/text()").InnerText;