John Riker

John Riker

  • NA
  • 85
  • 14.1k

Load XML without dealing with XSD?

Dec 10 2020 3:34 PM
I have an XML file that comes back with some online sources as well formed.  Only complaint is it doesn't have the referenced xsd file.  All the data I need is in this XML file already just need to get it loaded into my app.  
 
When I call the URL with:
 
  1. XmlDocument doc = new XmlDocument();  
  2.  doc.LoadXml(url);  
  3.  String jsonText = JsonConvert.SerializeXmlNode(doc);  
  4.  return jsonText;  
 
 I get back 
 
Unhandled Exception: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
 
 
This happens at the: doc.LoadXml(url);
 
Any thoughts? 

Answers (2)