C#XmlDocument,XDocument互换

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;

namespace WindowsFormService
{
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);
}
}
}
}

 

//XDocument转换成XmlDocument
// XmlDoc.LoadXml(XDoc.Document.ToString());

posted @ 2012-01-13 17:17  cotty  阅读(761)  评论(0编辑  收藏  举报