Question

I was wondering whether there is a way to create an object such that a list of such object does not need a root element. For example, if I wanted to create an XML like

<Dogs>
  <Dog>A</Dog>
  <Dog>B</Dog>
  <Dog>C</Dog>
</Dogs>

I could have the class Dogs which would be the root element and has a List<Dog>. Now supposed I want to get rid of the encapsulating element <Dogs>. So that the list of dog would look like

<Dog>A</Dog>
<Dog>B</Dog>
<Dog>C</Dog>

how should I construct my classes?

Was it helpful?

Solution

In XML this is not possible. The specification at http://www.w3.org/TR/xml/#NT-document clearly says that a document has one root element.

Your second XML-like code is therefore not an XML document, but a concatenation of three XML documents. But parsers aren't usually prepared for this kind of input.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top