Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

XML Tree with more than one root

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 04 Mar 2008 13:03 GMT
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.

Appreciate any help.

John
Jon Skeet [C# MVP] - 04 Mar 2008 13:12 GMT
> 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
Martin Honnen - 04 Mar 2008 14:42 GMT
> 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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.