Reputation: 7416
I'm designing an XML Schema for my website. One of the elements in the schema is called "comments", which is supposed to contain comments posted from users. I wan't to allow certain xhtml tags to be used: b, i, and u for styling. So far what I've done is to import the XHTML namespace, and then declare a complexType for my comments element:
<import namespace="http://www.w3.org/1999/xhtml"
schemaLocation="xhtml1-transitional.xsd" />
....
<element name="comments">
<complexType mixed="true">
<any minOccurs="0">
<element ref="xhtml:u"/>
<element ref="xhtml:b"/>
<element ref="xhtml:i"/>
</any>
</complexType>
</element>
But this doesn't seem to work! At least the XML Schema won't validate via the IBM XML Schema Quality Checker. The xhtml1-transitional.xsd file is in the same folder as the XML Schema.
Upvotes: 0
Views: 683
Reputation: 21658
You have a syntax error; <any/> can't have content. You may have to use instead (most likely) a repeating choice.
Upvotes: 1
Reputation: 2634
The easiest way would be to use a <[CDATA[ ... ]]>
section for the comments. I think you validate the tags in your application code, so you don't have to enforce the validation in the XSD again.
Since you want an XSD solution only, I think the simplest way would be to define the comments tag as a string and escape the html special chars:
<xsd:element name="comments" type="xsd:string" />
I don't think, that it would be a good way to go to include the actual tags as XML in the schema, since it is just arbitrary content (what's with valid HTML, which is invalid XML? For example <p>
without </p>
is valid HTML, but invalid in XML).
The XML special characters to escape
" & ' < >
Upvotes: 1