Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

Error on Trying to Read XML

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerry Viator - 28 Oct 2003 16:29 GMT
Hi all,

When I try to read the XML I get the error below and highlights this
(Do While MainReader.Read)?

Error:
A first chance exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.

Please help.

Friend Function CreateXMLfiles()

       'Write XML DEFAULT files

       Dim MainListWriter As XmlTextWriter = New XmlTextWriter(WorkingDir & "main.xml", System.Text.Encoding.UTF8)

       MainListWriter.Formatting = Formatting.Indented
       MainListWriter.Indentation = 2   'Indent tags by 2 characters.
       MainListWriter.QuoteChar = """"c 'Enclose attributes'  values in double quotes.
       MainListWriter.WriteStartDocument(True)
       MainListWriter.WriteComment("Main List Build")

       MainListWriter.WriteStartElement("Main List")

       MainListWriter.WriteStartElement("MAIN")
       MainListWriter.WriteAttributeString("Name", "Administration")
       MainListWriter.WriteElementString("sublist", "")
       MainListWriter.WriteEndElement()

       MainListWriter.WriteStartElement("MAIN")
       MainListWriter.WriteAttributeString("Name", "Search")
       MainListWriter.WriteElementString("sublist", "")
       MainListWriter.WriteEndElement()
   
       MainListWriter.WriteStartElement("MAIN")
       MainListWriter.WriteAttributeString("Name", "----------------------")
       MainListWriter.WriteEndElement()

       MainListWriter.WriteStartElement("MAIN")
       MainListWriter.WriteAttributeString("Name", "ERCP")
       MainListWriter.WriteElementString("sublist", "4")
       MainListWriter.WriteEndElement()    

       MainListWriter.WriteEndDocument()
       MainListWriter.Close()

 End Function

Friend Function LoadList(ByVal ElemName As String)

       Dim MainReader As New XmlTextReader(WorkingDir & "main.xml")

       Do While MainReader.Read
           Select Case MainReader.NodeType
               Case XmlNodeType.Document  ' The node is an Element
                   

               Case XmlNodeType.Element

           End Select
       Loop

       MainReader.Close()
End Function

Thanks
Gerry
Gerry Viator - 28 Oct 2003 17:57 GMT
I figured out the problem:

MainListWriter.WriteStartElement("Main List")

("Main List") has a space there, once I changed this to ("MainList"), the problem went away.

Can you not have spaces as a name? Is there a way to do this?

thanks
Gerry

 Hi all,

 When I try to read the XML I get the error below and highlights this
 (Do While MainReader.Read)?

 Error:
 A first chance exception of type 'System.Xml.XmlException' occurred in system.xml.dll
 Additional information: System error.

 Please help.

  Friend Function CreateXMLfiles()

         'Write XML DEFAULT files

         Dim MainListWriter As XmlTextWriter = New XmlTextWriter(WorkingDir & "main.xml", System.Text.Encoding.UTF8)

         MainListWriter.Formatting = Formatting.Indented
         MainListWriter.Indentation = 2   'Indent tags by 2 characters.
         MainListWriter.QuoteChar = """"c 'Enclose attributes'  values in double quotes.
         MainListWriter.WriteStartDocument(True)
         MainListWriter.WriteComment("Main List Build")

         MainListWriter.WriteStartElement("Main List")

         MainListWriter.WriteStartElement("MAIN")
         MainListWriter.WriteAttributeString("Name", "Administration")
         MainListWriter.WriteElementString("sublist", "")
         MainListWriter.WriteEndElement()

         MainListWriter.WriteStartElement("MAIN")
         MainListWriter.WriteAttributeString("Name", "Search")
         MainListWriter.WriteElementString("sublist", "")
         MainListWriter.WriteEndElement()
     
         MainListWriter.WriteStartElement("MAIN")
         MainListWriter.WriteAttributeString("Name", "----------------------")
         MainListWriter.WriteEndElement()

         MainListWriter.WriteStartElement("MAIN")
         MainListWriter.WriteAttributeString("Name", "ERCP")
         MainListWriter.WriteElementString("sublist", "4")
         MainListWriter.WriteEndElement()    

         MainListWriter.WriteEndDocument()
         MainListWriter.Close()

   End Function

  Friend Function LoadList(ByVal ElemName As String)

         Dim MainReader As New XmlTextReader(WorkingDir & "main.xml")

         Do While MainReader.Read
             Select Case MainReader.NodeType
                 Case XmlNodeType.Document  ' The node is an Element
                     

                 Case XmlNodeType.Element

             End Select
         Loop

         MainReader.Close()
  End Function

 Thanks
 Gerry
Kevin Yu [MSFT] - 29 Oct 2003 02:45 GMT
Hi Gerry,

The XML tag cannot contain spaces in the tag name. Because if there's a
space in it, the parser will consider the following part of the space as an
attribute.

Kevin Yu
Signature

=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


--------------------
| From: "Gerry Viator" <viatorg@musc.edu>
| References: <ORRJShWnDHA.3256@tk2msftngp13.phx.gbl>
[quoted text clipped - 48 lines]
|           MainListWriter.WriteStartElement("MAIN")
|           MainListWriter.WriteAttributeString("Name",
"----------------------")
|           MainListWriter.WriteEndElement()
|           MainListWriter.WriteStartElement("MAIN")
[quoted text clipped - 17 lines]
|   Thanks
|   Gerry
Gerry Viator - 29 Oct 2003 13:51 GMT
Thanks

Gerry

> Hi Gerry,
>
[quoted text clipped - 88 lines]
> |   Thanks
> |   Gerry

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.