如何根据属性(类型字符串)获取xml节点的innertext?
我的XML文件看起来如下。
<?xml version="1.0" encoding="UTF-8" ?>
<office:document-content office:version="1.2">
<office:body>
<office:text>
<table:table table:name="Tabelle6" table:style-name="Tabelle6">
<table:table-row>
<table:table-cell table:style-name="Tabelle6.A1" office:value-type="string">
<text:p text:name="Invoice" text:style-name="P6">0001</text:p>
</table:table-cell>
</table:table-row>
</table:table>
</office:text>
</office:body>
</office:document-content>
我想从此xml文件中获取发票号(0001)。 我的代码看起来像这样
var xml = XDocument.Load(filePath);
var query = from item in xml.Elements("text:p")
where (string)item.Attribute("text:name").Value == "Invoice"
select item.Value;
如果我执行此操作,则会收到错误消息:
&#39;:&#39;字符,十六进制值0x3A,不得包含在名称中。
也许这很重要,content.xml
是提取的.odt
- 文件的一部分。