Reputation: 65
I have to validate XML file that contains embedded XML, with XML Schema. Correctness of the inner XML doesn't interest me. Which type should I use in XML Schema for this type of content? Simple xs:string
doesn't work.
Upvotes: 2
Views: 2358
Reputation: 31453
You have a number of alternatives for embedding XML within another XML document.
xs:any:
You can use the xs:any
type in your schema (link). However you will need to include a schema for the embedded XML (which will be used to validate it).
Alternatively, xs:string
can be made to work if you either embed the inner XML within a CDATA
section or escape all the <
and &
characters.
CDATA
section:
<InnerXml>
<![CDATA[
<InnerXmlRoot>
<InnerXmlContent>One & Two</InnerXmlContent>
</InnerXmlRoot>
]]>
</InnerXml>
The only thing you need to be careful of with this approach is that the inner XML cannot contain CDATA
sections as the allowed content cannot contain ]]>
(see the XML specification).
Character escaping:
<InnerXml>
<InnerXmlRoot>
<InnerXmlContent>One & Two</InnerXmlContent>
</InnerXmlRoot>
</InnerXml>
Upvotes: 1