Re: [PHP-XML-DEV] Re: DOMDocument::schemaValidate() - group nodes inside choice nodes

[email protected] (Christian Stocker) Fri, 12 Nov 2004 06:24:09 +0100
Newsgroups php.xml.dev
Message-ID <[email protected]>
Hi

It's not PHPs task to validate your schema, the library used behind, 
libxml2, is doing that. So if something doesn't validate, but it should, 
it's not our "fault". libxml2 has has still no feature complete XSD 
Support (AFAIK), but they made some big progress latetly. It's therefore 
a good idea to use one of the latest libxml2 releases and check, if they 
maybe fixed that issue.

I didn't look at your XSD and check, if it's valid at all. I'm no XSD 
expert, but I assume, you checked it already with another validator ;)

chregu

On 12.11.2004 1:43 Uhr, nick eby wrote:
> 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" );
> ?>
> 

-- 
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60  | fax +41 1 240 56 71
http://www.bitflux.ch  |  [email protected]  |  gnupg-keyid 0x5CE1DECB