【发布时间】:2015-04-01 12:28:24
【问题描述】:
我有一个复杂的 XML,想在 C# 中使用 LINQ 解析它:
<?xml version="1.0"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xml:space="preserve" w:embeddedObjPresent="no">
<w:docPr xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
<w:displayBackgroundShape/>
<w:view w:val="print"/>
<w:zoom w:percent=""/>
<w:defaultTabStop w:val="708.1365"/>
<w:docVars/>
</w:docPr>
<w:body>
<w:p xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
<w:pPr>
<w:pStyle w:val="Author_28_s_29_"/>
</w:pPr>
<w:r>
<w:rPr><w:rStyle w:val="T4"/></w:rPr>
<w:t>Satyam</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T5"/>
</w:rPr>
<w:t>Singh</w:t>
</w:r>
<w:r>
<w:t>,</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T6"/>
</w:rPr>
<w:t>Disha</w:t>
</w:r>
<w:r>
<w:t>A</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T4"/>
</w:rPr>
<w:t>.</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T5"/>
</w:rPr>
<w:t>Shah</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T7"/>
</w:rPr>
<w:t>,2,*</w:t>
</w:r>
<w:r>
<w:t>,</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T4"/>
</w:rPr>
<w:t>Karan</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rStyle w:val="T5"/>
</w:rPr>
<w:t>Bhutwala</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>
所以我想得到:
Author_28_s_29_=萨蒂扬·辛格
Author_28_s_29_=迪沙阿沙
Author_28_s_29_=卡兰·布特瓦拉
.
.
等等。
我尝试了几个解析选项。这里的逻辑可以理解为
parent().children.where(r).(t).value
【问题讨论】:
-
请展示一个简短但完整的程序,说明您尝试过的内容,并说明您的预期与发生的情况。 (如果您将 XML 格式化以使结构清晰可见,这也真的会有所帮助。)
标签: c# .net xml linq linq-to-xml