views:

21

answers:

1

In Visual Studio, I have an XML file (with .xml extension) which contains an XML fragment that I use in my program:

<tag1>
data 
...
</tag1>
<tag2>
data 
...
</tag2>

Visual Studio shows me an error in the error list: "XML document cannot contain multiple root level elements".

But this is not a complete document, just a fragment that will be reused. I want to keep my 2 roots in my fragment. How can I get rid of the error message?

Thanks

+2  A: 

How can I get rid of the error message?

I don't think you can.

XML Documents have only a single root, there is no such thing as a "xml fragment document".

Two options:

  • Use two files, one for each fragment.
  • Put a placeholder root element in, and then use its children when using this content.

(Or put up with the error.)

Richard