我需要解析XMind包中的content.xml文件。
文件如下所示
<xmap-content xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:fo="http://www.w3.org/1999/XSL /Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" version="2.0">
<sheet id="sdfasdfsdf">
<title> Sheet1 </title>
</sheet>
<sheet id="fgasdfgasr">
<title> Sheet2 </title>
</sheet>
<xmap-content>我需要得到所有工作表的标题列表。
我正在使用XPathExpression expr = navigator.Compile("//sheet");
但我猜它不起作用
该怎么做。任何建议或代码都可以。
要提前做好准备。
发布于 2011-11-10 17:09:23
您的XML定义了默认名称空间:urn:xmind:xmap:xmlns:content:2.0。因此您需要将其传递给带有前缀的XML引擎,然后使用表达式:
//ns:sheet或者用另一种方式:
//*[local-name() = 'sheet']发布于 2011-11-10 17:02:04
试一试
XPathExpression expr = navigator.Compile("xmap-content/sheet");编辑:
string st = @"<xmap-content xmlns=""urn:xmind:xmap:xmlns:content:2.0"" xmlns:fo=""http://www.w3.org/1999/XSL /Format"" xmlns:svg=""http://www.w3.org/2000/svg"" xmlns:xhtml=""http://www.w3.org/1999/xhtml"" xmlns:xlink=""http://www.w3.org/1999/xlink"" version=""2.0"">
<sheet id=""sdfasdfsdf"">
<title> Sheet1 </title>
</sheet>
<sheet id=""fgasdfgasr"">
<title> Sheet2 </title>
</sheet>
</xmap-content>";
XmlDocument document = new XmlDocument();
document.LoadXml(st);
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("xm", "urn:xmind:xmap:xmlns:content:2.0");
var titles = document.SelectNodes("//xm:sheet/xm:title", manager);https://stackoverflow.com/questions/8076910
复制相似问题