|
-
May 15th, 2003, 04:04 PM
#1
Thread Starter
Hyperactive Member
Reading an XML file with multiple root elements.
Hey All,
Using DataSet.ReadXML or the XMLTextReader function brings up an exception.
Basically it says that there is more than one root element in my XML file, my files may or may not have this, is there anyway of ignoring this exception and reading the rest of the file?
TIA.
-
May 15th, 2003, 04:18 PM
#2
PowerPoster
I thought that a 'well-formed' XML document can only have one root. If that is truly the case, then the dataset will probably always give you an error because the document has to be well formed in order for it to read it.
-
May 15th, 2003, 04:21 PM
#3
PowerPoster
The statement about well formed xml is this:
There is exactly one element, called the root, or document element, no part of which appears in the content of any other element. For all other elements, if the start-tag is in the content of another element, the end-tag is in the content of the same element. More simply stated, the elements, delimited by start- and end-tags, nest properly within each other.
I got that from the specification pdf here:
http://www.w3.org/TR/1998/REC-xml-19980210.pdf
-
May 15th, 2003, 04:29 PM
#4
Thread Starter
Hyperactive Member
They aren't my XML files, therefore I have no control over their content.
There must be a way around it...surely.
I REALLY don't want to have to use standard I/O.
Any Ideas?
-
May 15th, 2003, 04:49 PM
#5
Fanatic Member
I'll whack on it, could you please post some sample xml that is giving you problems?
-
May 15th, 2003, 05:06 PM
#6
A work around may be to upon it as text and add a root element in then save it as a temp file and open the temp file as xml. Just insert <root> before everything else or after any processing information and add </root> to the very end after everything. Then you have a well formed xml document.
-
May 15th, 2003, 05:10 PM
#7
PowerPoster
Originally posted by Edneeis
A work around may be to upon it as text and add a root element in then save it as a temp file and open the temp file as xml. Just insert <root> before everything else or after any processing information and add </root> to the very end after everything. Then you have a well formed xml document.
That is a good idea... I didn't even think of that...lol.
You could use a string builder object, then add the parts together real quick, and maybe use the string itself for the ReadXml method.
-
May 17th, 2003, 07:27 AM
#8
Thread Starter
Hyperactive Member
Slow_Learner,
Sure...
Main File:
<root>
<an_element1 anattribute="0">
ElText1
</an_element1>
<an_element2 anattribute="0">
ElText2
</an_element2>
<include file="example1.xml"/>
</root>
Example1.xml:
<ex>
<hello>
Goodbye
</hello>
</ex>
<ex> - Duplicate root element
<hello>
Hi
</hello>
</ex>
As you can see, there is a main file, and the main file includes other files. The files it includes are obviously not formatted correctly.
I could probably figure out a way to merge all the files into the main file, but I'd need to move them back out into individual files after editing is complete.
Edneeis, I thought of that too, but I'll look at it as a last resort.
Any more ideas?
Thanks guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|