Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. XML / XSL
  4. Exception when reading xml file???

Exception when reading xml file???

Scheduled Pinned Locked Moved XML / XSL
csharpxmlquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richiemac
    wrote on last edited by
    #1

    Hi all, I'm trying to read a file wuth C#. The file contains the following: Microsoft Mary 100 0 and the code to read is: voice_reader.Read(); voice_reader.ReadStartElement("voice_config"); voice_reader.ReadStartElement("voice_type"); m_voice = voice_reader.ReadString(); voice_reader.ReadEndElement(); voice_reader.ReadStartElement("voice_volume"); m_volume = voice_reader.ReadContentAsInt(); voice_reader.ReadEndElement(); voice_reader.ReadStartElement("voice_rate"); m_rate = voice_reader.ReadContentAsInt(); voice_reader.ReadEndElement(); voice_reader.ReadEndElement(); I'm getting the following exception thrown: Exception : Unexpected XML Declaration. The XML Declaration should be the first node in the document, and no whitespace characters are allowed to appear before it, Line 1 position 100

    G 1 Reply Last reply
    0
    • R richiemac

      Hi all, I'm trying to read a file wuth C#. The file contains the following: Microsoft Mary 100 0 and the code to read is: voice_reader.Read(); voice_reader.ReadStartElement("voice_config"); voice_reader.ReadStartElement("voice_type"); m_voice = voice_reader.ReadString(); voice_reader.ReadEndElement(); voice_reader.ReadStartElement("voice_volume"); m_volume = voice_reader.ReadContentAsInt(); voice_reader.ReadEndElement(); voice_reader.ReadStartElement("voice_rate"); m_rate = voice_reader.ReadContentAsInt(); voice_reader.ReadEndElement(); voice_reader.ReadEndElement(); I'm getting the following exception thrown: Exception : Unexpected XML Declaration. The XML Declaration should be the first node in the document, and no whitespace characters are allowed to appear before it, Line 1 position 100

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      // You are not advancing through the document, Example: using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace XmlRdr { class Program { static void Main(string[] args) { XmlReader voice_reader = null; try { voice_reader = XmlReader.Create(@"C:\voice_config.xml"); while (voice_reader.Read()) { if (voice_reader.NodeType == XmlNodeType.Element) { switch (voice_reader.Name) { case "voice_config": break; case "voice_type": Console.WriteLine(voice_reader.ReadString()); break; case "voice_volume": Console.WriteLine(voice_reader.ReadString()); break; case "voice_rate": Console.WriteLine(voice_reader.ReadString()); break; default: break; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (voice_reader != null && voice_reader.ReadState != ReadState.Closed) { voice_reader.Close(); } } } } }

      R 1 Reply Last reply
      0
      • G George L Jackson

        // You are not advancing through the document, Example: using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace XmlRdr { class Program { static void Main(string[] args) { XmlReader voice_reader = null; try { voice_reader = XmlReader.Create(@"C:\voice_config.xml"); while (voice_reader.Read()) { if (voice_reader.NodeType == XmlNodeType.Element) { switch (voice_reader.Name) { case "voice_config": break; case "voice_type": Console.WriteLine(voice_reader.ReadString()); break; case "voice_volume": Console.WriteLine(voice_reader.ReadString()); break; case "voice_rate": Console.WriteLine(voice_reader.ReadString()); break; default: break; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (voice_reader != null && voice_reader.ReadState != ReadState.Closed) { voice_reader.Close(); } } } } }

        R Offline
        R Offline
        richiemac
        wrote on last edited by
        #3

        Got it now. Knew it would be simple.:doh:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups