tags:

views:

121

answers:

3
+1  Q: 

LoadXML Problem C#

I have a code snippet :

XmlDocument doc = new XmlDocument();
    try
    {
        doc.LoadXml(xmlPath);
    }
    catch (Exception ex)
    {
        string exMessage = ex.Message; 
    }

The XML looks like this

   <?xml version="1.0" encoding="UTF-8"?>
      <MimeTypes>
       <MimeType>
         <Extension>.3dm</Extension>
         <Value>x-world/x-3dmf</Value>
       </MimeType>
      </MimeTypes>

Its producing this error:

Data at the root level is invalid. Line 1, position 1.

Any idea what's wrong?

+7  A: 

Use doc.Load(xmlPath). LoadXML is for loading an XML string.

ristonj
+2  A: 

You're passing a file path to a parameter that should contain the XML itself.

Daniel Earwicker
+1  A: 

does xmlPath contains the whole xml or a path to a file that contains it? The LoadXml method expects the actual XML, not a path to a file. If you want to load the xml using a path, using the Load method.