No matter what you do, if you append one
valid non-empty XML to some other
valid non-empty XML, you obtain some text which is always, in all cases is
not a well-formed XML. Even if the second XML does not contain the prolog you quoted in your question. This is obvious from the XML definition: it always has only one root element.
[EDIT #1]
You can always load XML from string. In .NET FCL, there are at least three different XML parsers. This is my short overview of the parsing possibilities:
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
The real question is: why loading XML from UI? Do you really hope that your user will enter valid XML in some text box? Why?
[EDIT #2]
To read and write XML, you can use the following options:
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
and System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that of XmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
Your approach to asking questions is pretty bad. You always need to explain your ultimate goals. There is a very little interest in helping to do something weird, without knowing if it makes sense of not. Try to isolate your goals from your present understanding of how you want to achieve them. If your understanding is wrong, you still have a chance to get a good advice. Only if you explain your goals.
—SA