On Sun, 31 Oct 2004 19:08:04 +, Dusty Bin [EMAIL PROTECTED] wrote:
I am trying to validate an XML document, using
DomDocument::schemaValidate() as in the following code:
?php
$txt =EOT
?xml version=1.0?
Article xmlns='http://www.example.com/xml'
ItemItemText/Item
/Article
EOT;
$dom = new DOMDocument();
$dom-loadXML($txt);
if ($dom-schemaValidate(Article.xsd)) {
print $dom-saveXML();
}
?
The schema I am trying to validate against is:
?xml version=1.0 ?
xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema;
xs:element name=Article
xs:complexType
xs:sequence
xs:element name=Item maxOccurs=unbounded/
/xs:sequence
/xs:complexType
/xs:element
/xs:schema
This produces the following output:
Warning: Element Article not declared in E:\PHPTest\testXML.php on line 10
Warning: Element Article not declared in E:\PHPTest\testXML.php on line 10
Aren't you missing any namespace declaration in your Schema File?
I'm no XML Schema Expert at al, so I took trang and let it made one
out of your XML and it produced the following:
?xml version=1.0 encoding=UTF-8?
xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema;
elementFormDefault=qualified
targetNamespace=http://www.example.com/xml;
xmlns:x=http://www.example.com/xml;
xs:element name=Article
xs:complexType
xs:sequence
xs:element ref=x:Item/
/xs:sequence
/xs:complexType
/xs:element
xs:element name=Item type=xs:NCName/
/xs:schema
And this validates (at least with libxml2 version 2.6.14, the PHP
version doesn't matter, since all the validation is done by
libxml2...)
chregu
If I remove the default namespace from the article tag, the XML
validates correctly. I seem to recollect that namespace support is not
fully implemented, so my question is, is this a bug, or just something
not yet implemented, or is there an obvious blunder in what I am trying
to do, which I cannot see.
Best regards. . . Dusty
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php