Re: DOMDocument::schemaValidate() - group nodes inside choice nodes
| From: | nick eby | Date: | Fri, 12 Nov 2004 00:43:52 +0000 |
| Subject: | Re: DOMDocument::schemaValidate() - group nodes inside choice nodes | ||
| References: | 1 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-502@lists.php.net to get a copy of this message | ||
here is a full script that much better illustrates what i'm talking about.
note the difference between the two XSD's. i contend that the document
should validate against both, but i suspect that i've just been looking at
it for too long.
<?
$prolog = '<?xml version="1.0"?>';
$xsd = $xsd2 = $xml = $prolog;
$xsd .= <<<EOT
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="customer">
<xs:complexType>
<xs:choice>
<xs:element ref="customer-id"/>
<xs:group ref="customerinfo"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="customer-id" type="xs:long" />
<xs:group name="customerinfo">
<xs:sequence>
<xs:element ref="name" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:group>
<xs:element name="name" type="xs:string"></xs:element>
</xs:schema>
EOT;
$xsd2 .= <<<EOT
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="customer">
<xs:complexType>
<xs:choice>
<xs:element ref="customer-id"/>
<xs:group name="customer-info">
<xs:sequence>
<xs:element ref="name" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:group>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="customer-id" type="xs:long" />
<xs:element name="name" type="xs:string"></xs:element>
</xs:schema>
EOT;
$xml .= <<<EOT
<customer>
<name>Bob Eubanks</name>
</customer>
EOT;
$doc = DOMDocument::loadXML($xml);
echo ($doc->schemaValidateSource($xsd) ? " xsd1 OK " : " xsd1 NOT OK" );
echo "<BR/>";
echo ($doc->schemaValidateSource($xsd2) ? " xsd2 OK " : " xsd2 NOT OK" );
?>