Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
I hit a exception in parsing XML file
Message
De
11/01/2005 07:31:44
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
I hit a exception in parsing XML file
Divers
Thread ID:
00975982
Message ID:
00975982
Vues:
45
Dear expert:
I hit a strange error message while i am parsing a xml from a URL in C#.
Here is the source code:
                 static void Main(string[] args)
	  {
	      String URLString = "c:\\books.xml";
	      XmlTextReader reader = new XmlTextReader(URLString);
	      reader.WhitespaceHandling = WhitespaceHandling.None;
               
               while (reader.Read())
	      {
		switch(reader.NodeType)
		{
		  case XmlNodeType.Element:  //The node is an element.
		     Console.Write("<" + reader.Name);
		     while (reader.MoveToNextAttribute()) //Read the attributes.
		       Console.Write(" " + reader.Name + "='" + reader.Value + "'");
		       
                         Console.Write(">");
		       Console.WriteLine(">");
		       break;
		  case XmlNodeType.Text:  //Display the text in each element.
		       Console.WriteLine(reader.Value);
		       break;
		   case XmlNodeType.EndElement:  //Display the end of the element.
		       Console.Write("</" + reader.Name);
		       Console.WriteLine(">");
		       break;
		  }
	       }
	    }
The error message is:
Unhandled Exception: System.Xml.XmlException: The XML declaration is unexpected. Line 1, position 4.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()

Is there any mistaken in XML file?
The source code of XML :
     <?xml version="1.0" encoding="ISO-8859-1"?>
     <bookstore>
     <book genre="autobiography">
       <title>The Autobiography of Benjamin Franklin</title>
       <author>
         <first-name>Benjamin</first-name>
         <last-name>Franklin</last-name>
       </author>
       <price>8.99</price>
     </book>
     <book genre="novel">
       <title>The Confidence Man</title>
       <author>
         <first-name>Herman</first-name>
         <last-name>Melville</last-name>
       </author>
       <price>11.99</price>
     </book>
     <book genre="philosophy">
       <title>The Gorgias</title>
       <author>
         <name>Plato</name>
       </author>
       <price>9.99</price>
     </book>
   </bookstore>
Thanks for anyone helping me, Best wish and regards
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform