【问题标题】:Read xml data file into Windows.Data.Xml.Dom.XMLDocument将 xml 数据文件读入 Windows.Data.Xml.Dom.XMLDocument
【发布时间】:2015-08-03 08:53:09
【问题描述】:

我们如何将 xml 数据文件读入Windows.Data.Xml.Dom.XMlDocument? 以下代码仅适用于System.Xml.XmlDocument

XmlDocument myxml = XmlDocument.Load("abc.xml");

【问题讨论】:

  • 确保首先调用构造函数。我最近在 excel VBA 中使用了这个:Dim fedbook As New MSXML2.DOMDocument60 fedbook.LoadXML strData。您可以将文件作为字符串读取,然后使用 LoadXml()
  • 您找到解决方案了吗?

标签: c# xml windows-store-apps winrt-xaml


【解决方案1】:

我把xml文件内容读成字符串,然后用LoadXml()

  string fileContent;
  StorageFile tileTemplateFile = 
        await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"<path to file>"));
  using (StreamReader reader = 
        new StreamReader(await tileTemplateFile.OpenStreamForReadAsync()))
  {
      fileContent = await reader.ReadToEndAsync();
  }

  XmlDocument tileXml = new XmlDocument();
  tileXml.LoadXml(fileContent);

我从this answer 获得了大部分代码。

【讨论】:

    【解决方案2】:

    您需要执行以下操作。

    XmlDocument xmlDoc = new XmlDocument();  
    xmlDoc.LoadXml(<string representation of your xml>);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-03
      • 2011-07-24
      • 2012-02-24
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      相关资源
      最近更新 更多