CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    27

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

    Wondering what is it that I am doing wrong (and how I can fix it) ... I am trying to learn how to read XML file and created a little program below to start testing what I have read but keep getting error "Data at the root level is invalid. Line 1, position 1"

    The line where the error is coming from is the line "xmldoc.LoadXml(strFile)".. any ideas?

    Thank you so much for all the help you could give.

    Gratefully,
    Matt

    Code:
      Private Sub cmdReadXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   
    Handles cmdReadXML.Click
          Dim clsk As New clsHx
          clsk.ReadXML("e:\xml\mama.xml")
      End Sub
    
      Below is the a subroutine in my clsHx class:
      Public Sub ReadXML(ByVal strFile As String)
          Dim xmldoc As New XmlDocument
    
          xmldoc.LoadXml(strFile)
          MsgBox(xmldoc.GetElementsByTagName("myfirstdata"))
          MsgBox(xmldoc.GetElementsByTagName("mySecondData"))
    
      End Sub
    Below is the content of the XML file which is located in e:\xml\mama.xml:
    Code:
      <?xml version="1.0" ?> 
      <myData>
      <myrecord>
      <myfirstdata>String for my second element</myfirstdata> 
      <mySecondData>Second data element here</mySecondData> 
      </myrecord>
      <myrecord>
      <myfirstdata>record2 for my second element</myfirstdata> 
      <mySecondData>record2mySec Second data element here</mySecondData> 
      <myThirdData>recorderData data element here</myThirdData> 
      </myrecord>
      </myData>
    Last edited by HanneSThEGreaT; May 6th, 2010 at 08:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured