来自xmlDocument的xDocument

时间:2012-11-15 15:32:56

标签: windows-8 linq-to-xml

我正在尝试将XML文档转换为适用于Windows 8 metro应用程序的XDocument。我尝试了Converting XDocument to XmlDocument and vice versaFast Way to convert XMLDocument to XDocument但由于XmlNodeReader似乎不存在而失败了。

同样我也试过Error :- The XmlReader state should be Interactive on XDocument.Load,但在这种情况下,OuterXml似乎不存在。我正在使用的代码是:

using MyApp.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Data.Xml.Dom;
using Windows.Data.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Xml;


public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
    using (var nodeReader = new XmlNodeReader(xmlDocument))
    {            
       nodeReader.MoveToContent();         
       return XDocument.Load(nodeReader);         
    }        
 }


protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{

    Uri uri = new Uri("My html uri goes here");
    XmlDocument xddoc = await XmlDocument.LoadFromUriAsync(uri);
    var xdoc = xddoc.ToXDocument();

    // Reading data from xdoc next.
}

我在另一边的xml文件如下 -

<Books>
   <Book Name="foo">
      <Details Author="foo foo" />
  </Book>
</Books>

0 个答案:

没有答案