简体   繁体   English

操纵xml文件的最佳方法是什么?

[英]What is the best method to manipulate xml files?

I want to manipulate XML files. 我想操纵XML文件。

...
<Document Id="1091">
      <Indexes>
        <Index Name="MODD" Value="aaa" />
        <Index Name="DDAT" Value="bbb" />
        <Index Name="CDAT" Value="ccc" />
        <Index Name="MDAT" Value="ddd" />
        <Index Name="DOCN" Value="eee" />
        <Index Name="STAT" Value="fff" />
        ...
      </Indexes>
</Document>
<Document Id="2088">
      ...

I have retrieve the value of some index randomly. 我已经随机检索了一些索引的值。 I would avoid the loop on all the indexes. 我会避免所有索引上的循环。 What is the tool you advise me to use and why? 您建议我使用什么工具,为什么?

  • load the file as a text file and use RegEx 将文件加载为文本文件并使用RegEx
  • load the xml file and use XPath 加载xml文件并使用XPath
  • load the xml file and use Linq to Xml 加载xml文件并使用Linq到Xml
  • generate the classes with xsd.exe or xsd2code 用xsd.exe或xsd2code生成类
  • another approach 另一种方法

I'd go with LinqToXml. 我会选择LinqToXml。 Good syntax and easy to use! 良好的语法,易于使用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM