| | |
Strange Root element missing exception in XML
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
I get an error trying to parse som XML. The error is
The exception gets thrown during
System.Xml.XmlException: Root element is missing.. , and I can't understand why. Here is the code I run: C# Syntax (Toggle Plain Text)
MemoryStream xmlStream = new MemoryStream(); StreamWriter xmlStreamWriter = new StreamWriter(xmlStream); String xml = "<html>\n<body>\n\n<h1>My First Heading</h1>\n\n<p>My first paragraph.</p>\n\n</body>\n</html>"; xmlStreamWriter.Write(xml); xmlStreamWriter.Flush(); XmlReader reader = XmlReader.Create(xmlStream); StringWriter jsonStringWriter = new StringWriter(); JsonWriter writer = new JsonTextWriter(jsonStringWriter); writer.Formatting = Newtonsoft.Json.Formatting.Indented; JsonMLParser.Encode(reader, writer);
The exception gets thrown during
JsonMLParser.Encode() during reader.MoveToContent() which is the first call to the xml-reader. Last edited by Alxandr; 27 Days Ago at 6:29 pm.
3
#2 27 Days Ago
Reset the stream position before instantiate the reader.
C# Syntax (Toggle Plain Text)
xmlStream.Position = 0; XmlReader reader = XmlReader.Create(xmlStream); reader.MoveToContent(); .....
Failure is not fatal, but failure to change might be. - John Wooden
0
#3 27 Days Ago
Perhaps because you're trying to parse html/xhtml with an xml reader, and they're different formats.
0
#4 27 Days Ago
•
•
•
•
Reset the stream position before instantiate the reader.
C# Syntax (Toggle Plain Text)
xmlStream.Position = 0; XmlReader reader = XmlReader.Create(xmlStream); reader.MoveToContent(); .....
![]() |
Similar Threads
- A little help with XML (Java)
- Visual webjavaservrfaces and database (JSP)
- XML to XML transformation (XML, XSLT and XPATH)
- Probblem with element Display via vb (XML, XSLT and XPATH)
- Help StreamReader with DataGrid XML (VB.NET)
- Parse a XML element with AJAX (JavaScript / DHTML / AJAX)
- parsing error (XML file-java-schema) (Java)
Other Threads in the C# Forum
- Previous Thread: C# Serial Ports
- Next Thread: How to display values from database into datagridview
| Thread Tools | Search this Thread |
actionscript3 api asp.net blogger blogging code delete development error flash flipbook gdata google html kernel linspire linus linux microsoft news node nodes openoffice optimisation php programming rss serialization standards swappingxmlfromflash swappingxmlnodes swf tanenbaum tannenbaum text torvalds transform txttoxmlconverter vb2008 w3c web xml xmlnotloading xmlonserver xsl xslt







