I have written an XML doc that's fed into XSLT then XSLFO, it all works fine and pr开发者_C百科oduces lovely formatted pdf's. The schema I have written is throwing an error which is a problem as the structure is the nub of the project.
XML doc example:
<sect>
<summ>
<p>
Here's some text.
</p>
<img src="www.someaddress.com"/>
<p>
Here's more text.
</p>
</summ>
<sect>
The corresponding schema's (to save space I have removed some elements from each of the xs:choice's):
<xs:element name="img">
<xs:complexType>
<xs:attribute name="src" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="summ">
<xs:complexType>
<xs:choice>
<xs:element maxOccurs="unbounded" ref="p"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="img"/>
</xs:choice>
</xs:choice>
<xs:attribute name="title"/>
</xs:complexType>
</xs:element>
<xs:element name="sect">
<xs:complexType mixed="true">
<xs:choice maxOccurs="unbounded">
<xs:element ref="summ"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="p">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="img"/>
</xs:choice>
</xs:complexType>
</xs:element>
I want to be able to allow to appear inside both inside and outside of "p", at the moment when I validate this against the schema it throws an error "cvc-complex-type.2.4.a: Invalid content was found starting with element 'img'. One of '{p}' is expected."
So ideally I'd want the following to be valid:
<sect>
<summ>
<p>
Here's some text.
</p>
<img src="www.someaddress.com"/>
<p>
<img src="www.someotheraddress.com"/>
</p>
</summ>
<sect>
If you can help then I'd be very grateful :)
<xs:element name="summ">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element minOccurs="1" ref="p"/>
<xs:element ref="img"/>
</xs:choice>
<xs:attribute name="title"/>
</xs:complexType>
精彩评论