Showing posts with label position 1. Show all posts
Showing posts with label position 1. Show all posts

Wednesday, October 22, 2014

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

If you getting error mention in subject, use the following way to load file:

   
   Dim iXmlDocument As XmlDocument  
   iXmlDocument = Getxmldocument(sFilePath)  
   LoadNodes(iXmlDocument)  
        
   Function Getxmldocument(ByVal sFilePAth As String) As XmlDocument  
   
     Dim xmlDOC As New XmlDocument  
   
     Using myXmlTextReader As New XmlTextReader(sFilePAth)  
       myXmlTextReader.XmlResolver = Nothing  
       Dim settings As XmlReaderSettings = New XmlReaderSettings()  
       settings.ValidationFlags = Schema.XmlSchemaValidationFlags.None  
       settings.ProhibitDtd = False  
       settings.ValidationType = ValidationType.None  
   
       Using reader As XmlReader = XmlReader.Create(myXmlTextReader, settings)  
         result.Load(reader)  
         reader.Close()  
       End Using  
   
       myXmlTextReader.Close()  
       settings = Nothing  
     End Using  
   
     Return xmlDOC  
   End Function  
      
   ' load nodes...  
   Public Function LoadNodes(ByRef xmlFileReader As XmlDocument) As Boolean  
   
     Dim xNodeList As XmlNodeList  
     Dim xNode As XmlNode  
     xNodeList = xmlFileReader.SelectNodes("/Tag1/innerTag1")  
     ......  
     .......  
   End Function