dev*_*van 3 c# xml xpath xmldocument
我是xpath匹配的新手。在这里,我有一个将XML包含作为字符串传递的方法。我将其转换为XmlDocument。
public static void getProjectDataInfo(string content) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(content);
}
Run Code Online (Sandbox Code Playgroud)
这是我的XML。它具有xmlns:my
<?xml version="1.0" encoding="UTF-8"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:Financial>
<my:Quote>
<my:CHARGE_TYPE>MRC</my:CHARGE_TYPE>
<my:Price>463.92</my:Price>
</my:Quote>
</my:Financial>
</my:myField>
Run Code Online (Sandbox Code Playgroud)
我只想获得
/my:myFields/my:Financial/my:Quote/my:Price
Run Code Online (Sandbox Code Playgroud)
但是我无法获取值,因此此XML具有xmlns。
请帮我。
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46");
var str = doc.XPathSelectElement("/root/ns:myFields/ns:Financial/ns:Quote/ns:Price", nsmgr)
.ToString(SaveOptions.DisableFormatting);
Console.WriteLine(str);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2494 次 |
| 最近记录: |