zoukankan      html  css  js  c++  java
  • 从 XmlDocument到XDocument的转换

    扩展XmlDocument

    public static class XmlDocumentExtensions
    {
      public static XDocument ToXDocument(this XmlDocument document)
      {
        return document.ToXDocument(LoadOptions.None);
      }

      public static XDocument ToXDocument(this XmlDocument document, LoadOptions options)
      {
        using (XmlNodeReader reader = new XmlNodeReader(document))
        {
          return XDocument.Load(reader, options);
        }
      }
    }

     

    使用例子

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<parent><child>text</child></parent>");

    XDocument
    xdoc = doc.ToXDocument();
    var children = xdoc.Document.Element("parent").Elements("child");
    foreach (var child in children)
    {
      Console.WriteLine(child.Value);
    }

     

    摘自:http://www.cnblogs.com/wangsu/archive/2010/03/31/1701849.html

  • 相关阅读:
    jar包和war包的区别:
    tail
    redis
    查看Linux操作系统版本
    CentOS 7.0 systemd代替service
    周刊(三月最后一期)
    周刊第四期
    周刊第三期
    周刊第二期
    周刊(第一期)
  • 原文地址:https://www.cnblogs.com/kinpauln/p/1769771.html
Copyright © 2011-2022 走看看