【发布时间】:2014-06-27 04:26:24
【问题描述】:
我有以下 XML
<?xml version="1.0" encoding="UTF-8"?>
<form:Documents xmlns:form="http://www.example.com/file.xsd" xmlns:addData="http://www.example.com/file2.xsd">
<_colored:_colored addData:DocumentState="Correct" xmlns:_colored="http://www.example.com/colored.xsd">
<_colored>
<_Field1>PB8996MT</_Field1>
</_colored>
</_colored:_colored>
</form:Documents>
我尝试通过编写以下 C# 代码来获取 _Field1 标记的内部文本:
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
string fieldValue = xmlDocument.SelectSingleNode("/form:Documents/_colored:_colored/_colored/_Field1").InnerText;
当我运行应用程序时,出现以下异常:
Unhandled Exception: System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed.
This query has a prefix, variable, or user-defined function.
【问题讨论】: