Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have xml file without root tag & I have used stringbuilder,xmltextwriter to generate this file.
how to set start root tag& end root tag for this.
Posted
Updated 20-Jun-12 21:53pm
v4
Comments
Wonde Tadesse 20-Jun-12 21:46pm    
May I ask why you need an xml file without root node?
Sergey Alexandrovich Kryukov 21-Jun-12 0:42am    
Wonde, you are so right, that your question is not even correct: you cannot call such thing XML. Whatever is not a well-formed XML is not XML at all. Please see my answer.
--SA
AmitGajjar 21-Jun-12 0:38am    
can you give us your sample code. so that we can correct it.
Sergey Alexandrovich Kryukov 21-Jun-12 0:44am    
Excuse me, what are you going to correct? non-well-formed XML (which is not XML at all then) or the code which should not work in principle? Such "problems" simply should not be considered -- please see my answer.
--SA
AmitGajjar 21-Jun-12 1:10am    
your right SA. but after looking at what oliver have created, we can suggest something. if he is misunderstand the concept of the xml. am i correct ?

1 solution

The answer is not simple, but is very simple. If you have something without a root node (which is properly called document element), this "something" is not XML at all, because this is not a well-formed XML text. You cannot work with such thing using anything related to XML. So, either use real XML, or forget about any .NET XML classes and create your own — from scratch (good luck with that :-)).

Let's see. Suppose you have the simplest example:
HTML
<!-- this is NOT XML: -->
<a>First node</a>
<b>Second node</b>


Load it in any Web browser, for a simple test. This is a typical result:
XML
XML Parsing Error: junk after document element
Location: [...]
Line Number 2, Column 1:<b>Second node</b>
^


That's it. Forget it.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900