> Can someone show me a sample on how to save
> and load an xml tree with multiple roots? Most
> trees have only one root node, but I want more
> than one root. I know how to create one root,
> but when it goes over that limit I don't know
> what to do.
There's no such thing. An XML document by definition only has a single
root element.
If you want to fake having more than that, put multiple elements under
a single genuine root element.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Marc Gravell - 04 Mar 2008 13:37 GMT
True, but in addition to document there is also fragment:
http://msdn2.microsoft.com/en-us/library/6bts1x50.aspx
But most DOM representations (such as XmlDocument) won't let you use this
approach; "document" is by far the more correct approach.
Marc
John - 04 Mar 2008 13:48 GMT
I just stumbled upon this.
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/TreeViewDataBinding.htm
>> Can someone show me a sample on how to save
>> and load an xml tree with multiple roots? Most
[quoted text clipped - 8 lines]
> If you want to fake having more than that, put multiple elements under
> a single genuine root element.
Jon Skeet [C# MVP] - 04 Mar 2008 14:11 GMT
> I just stumbled upon this.
>
> http://www.java2s.com/Code/CSharp/GUI-Windows-Form/TreeViewDataBinding.htm
I'm unclear how that's related to your original question. Yes, that
example happens to use XML to load and save a data set, but it
certainly won't be an XML document with multiple root elements, as such
a thing doesn't exist.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
John - 04 Mar 2008 20:02 GMT
I guess basically I have to use some other storage format if I want
to use multiple roots.
Thanks guys, I don't want to make this more difficult than it is.
John
>> I just stumbled upon this.
>>
[quoted text clipped - 4 lines]
> certainly won't be an XML document with multiple root elements, as such
> a thing doesn't exist.
Jon Skeet [C# MVP] - 04 Mar 2008 20:32 GMT
> I guess basically I have to use some other storage format if I want
> to use multiple roots.
Well, you don't have to change much - just create a root element with
the appropriate subelements.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Arto Viitanen - 05 Mar 2008 06:38 GMT
John kirjoitti:
> I guess basically I have to use some other storage format if I want
> to use multiple roots.
Instead of one XML document, you could have a set of XML documents. I
guess this is how XML databases work.
--
Arto Viitanen
> Can someone show me a sample on how to save
> and load an xml tree with multiple roots? Most
> trees have only one root node, but I want more
> than one root. I know how to create one root,
> but when it goes over that limit I don't know
> what to do.
XmlWriter with XmlWriterSettings and ConformanceLevel.Fragment allows
you to create a fragment with multiple root elements (respectively any
kind of top-level nodes) and XmlReader with XmlReaderSettings and
ConformanceLevel.Fragment allows you to read such fragments. Within the
.NET framework you can pass such an XmlReader to an XPathDocument to
then apply XPath. XmlDocument on the other hand does not allow that, it
needs a single root element to become its DocumentElement.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/