|
I am rather new at working with XSD schemas but have been catching on. This question is for something I haven't been able to find an answer to anywhere. Maybe that means that what I want to do is not possible, but I figured I would post the question anyway.
Is there a way to force an element to be able to have sub-elements, any type of sub-elements, but no text within it?
Here is the source XML I use:
<Group attrib1="..." attrib2="...">
<Title>My Title</Title>
<Content>
<!-- in here, any other element
tags are allowed, but straight
text should not be allowed -->
</Content>
</Group>
I got the basic XSD written for this XML structure and this is what it looks like:
<xs:element name="Content">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="ContentHeight" type="xs:string" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
Now, using this XSD to validate a test Group.xml file, I get a message "Element cannot contain text or whitespace. Content model is empty." This is fine, I don't want the Content tag to have text or whitespace, but even when I put all the source XML on one line and ensure there is no text or whitespace, I still get that error.
If I try to do something like this:
<Group attrib1="..." attrib2="...">
<Title>My Title</Title>
<Content>
<TableView attrib1="..." attrib2="..." />
</Content>
</Group>
I get an error "Element 'Content' has invalid child element 'TableView'". This is a big problem, as I need the <Content> tag to allow any type of element, *only* elements and not straight text. After playing with the XSD a little bit, I found that allowing mixed content (i.e. see mixed="true" on <xs:complexType> below) would get rid of the "Element cannot contain text or whitespace" message. This is not my ideal approach but I can live with it for now. But with the XSD below I still get the message that "Element 'Content' has invalid child element 'TableView'".
<xs:element name="Content">
<xs:complexType mixed="true">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="ContentHeight" type="xs:string" />
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
Any pointers to get around this would be greatly appreciated.
|