2

How can we read a xml data file into Windows.Data.Xml.Dom.XMlDocument? The following code is possible only for System.Xml.XmlDocument.

XmlDocument myxml = XmlDocument.Load("abc.xml");
Bells
  • 1,465
  • 1
  • 19
  • 30
  • Make sure you call the constructor 1st. I did it in excel VBA recently using this : Dim fedbook As New MSXML2.DOMDocument60 fedbook.LoadXML strData. You can read the file as a string and then use LoadXml() – jdweng Aug 03 '15 at 10:30
  • Did you find a solution? – Felix Jan 18 '16 at 19:02

2 Answers2

1

I read the xml file content to a string, and then use 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);

I got most of the code from this answer.

Community
  • 1
  • 1
Felix
  • 3,783
  • 5
  • 34
  • 53
-2

You need to do the following.

XmlDocument xmlDoc = new XmlDocument();  
xmlDoc.LoadXml(<string representation of your xml>);
pah
  • 4,700
  • 6
  • 28
  • 37
hary
  • 1
  • 1