【发布时间】:2018-02-26 02:15:30
【问题描述】:
如何检查 xml 文件中包含属性的连续节点(用逗号和空格分隔),该属性的值的整数部分增加 +1,并将匹配的(如果有)字符串写入文件使用XDocument 或XElement 方法?这是一个示例 xml 文件
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth <chk att="sdf1">A-list</chk>, <chk att="sdf2">B-list</chk>, <chk att="sdf3">X-list</chk> look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former <chk att="sdf14">lA-list</chk>, <chk att="sdf16">pB-list</chk>, <chk att="sdf3">sX-list</chk> architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse <chk att="sdf11">A-list</chk>, <chk att="sdf20">B-list</chk>, <chk att="sdf21">X-list</chk>, <chk att="sdf22">A-list</chk>, <chk att="sdf23">B-list</chk>, <chk att="sdf25">X-list</chk> of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
我想提取字符串
<chk att="sdf1">A-list</chk>, <chk att="sdf2">B-list</chk>, <chk att="sdf3">X-list</chk>
和
<chk att="sdf20">B-list</chk>, <chk att="sdf21">X-list</chk>, <chk att="sdf22">A-list</chk>, <chk att="sdf23">B-list</chk>
来自上面的 xml 文件? 我考虑过为此使用正则表达式 find 但我无法找到添加递增属性值的方法...
我该怎么做?
【问题讨论】:
标签: c# linq-to-xml