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.
I have to validate XML file that contains embedded XML, with XML Schema. Correctness
Share
You have a number of alternatives for embedding XML within another XML document.
xs:any:You can use the
xs:anytype 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:stringcan be made to work if you either embed the inner XML within aCDATAsection or escape all the<and&characters.CDATAsection:The only thing you need to be careful of with this approach is that the inner XML cannot contain
CDATAsections as the allowed content cannot contain]]>(see the XML specification).Character escaping: