XML Tree with more than one root

  • Thread starter Thread starter John
  • Start date Start date
J

John

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
 
John said:
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.
 
John said:
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.
 
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
 
John said:
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top