You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "David R." <da...@hotmail.com> on 2002/05/29 11:00:31 UTC

Can a schema be validated?

I am trying to parse the following schema (just like I would proceed to 
parse any XML document) in order to get the values of some of its elements 
and attributes. The problem is that parse() fails when validation is 
activated. My question is: can a schema be validated?


** email.xsd begin **

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:element name="email">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="from" type="xsd:string"/>
				<xsd:element name="to" type="xsd:string" maxOccurs="unbounded"/>
				<xsd:element name="subject" type="xsd:string"/>
				<xsd:element name="body" type="body_type"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>

	<xsd:complexType name="body_type">
		<xsd:sequence>
			<xsd:element name="font" type="font_type"/>
			<xsd:element name="content" type="xsd:string"/>
		</xsd:sequence>
	</xsd:complexType>

	<xsd:complexType name="font_type">
		<xsd:simpleContent>
			<xsd:extension base="xsd:string">
				<xsd:attribute name="size" type="xsd:integer" use="required"/>
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
</xsd:schema>

** email.xsd end **


The parser options that I am setting are the following:
- validationScheme = always
- doSchema = true
- validationSchemaFullChecking = true
- doNamespaces = true

The execution of parse() fails and I get these errors:

Error (3,58): Unknown element 'xsd:schema'
Error (3,58): Attribute '{http://www.w3.org/2000/xmlns/}xsd' is not declared 
for
element 'xsd:schema'
Error (4,28): Unknown element 'xsd:element'
Error (4,28): Attribute '{}name' is not declared for element 'xsd:element'
Error (5,20): Unknown element 'xsd:complexType'
Error (6,18): Unknown element 'xsd:sequence'
Error (7,49): Unknown element 'xsd:element'
Error (7,49): Attribute '{}name' is not declared for element 'xsd:element'
Error (7,49): Attribute '{}type' is not declared for element 'xsd:element'
Error (8,69): Unknown element 'xsd:element'
...

What am I doing wrong? Some help would be appreciated.


_________________________________________________________________
Únase con MSN Hotmail al servicio de correo electrónico más grande del 
mundo. http://www.hotmail.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Can a schema be validated?

Posted by Alberto Massari <al...@exln.com>.
David,
when you set the validation scheme to be "always", Xerces requires a schema 
for the document, and this document does not point to either a DTD or an 
XML Schema.
You should add a

<!DOCTYPE xsd:schema SYSTEM "http://www.w3.org/2001/XMLSchema.dtd" [
<!ENTITY % p 'xsd:'>
<!ENTITY % s ':xsd'>
]>

definition after the "<?xml version..." declaration

Alberto

At 11.00 29/05/2002 +0200, you wrote:
>I am trying to parse the following schema (just like I would proceed to 
>parse any XML document) in order to get the values of some of its elements 
>and attributes. The problem is that parse() fails when validation is 
>activated. My question is: can a schema be validated?
>
>
>** email.xsd begin **
>
><?xml version="1.0" encoding="UTF-8"?>
>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>         <xsd:element name="email">
>                 <xsd:complexType>
>                         <xsd:sequence>
>                                 <xsd:element name="from" type="xsd:string"/>
>                                 <xsd:element name="to" type="xsd:string" 
> maxOccurs="unbounded"/>
>                                 <xsd:element name="subject" 
> type="xsd:string"/>
>                                 <xsd:element name="body" type="body_type"/>
>                         </xsd:sequence>
>                 </xsd:complexType>
>         </xsd:element>
>
>         <xsd:complexType name="body_type">
>                 <xsd:sequence>
>                         <xsd:element name="font" type="font_type"/>
>                         <xsd:element name="content" type="xsd:string"/>
>                 </xsd:sequence>
>         </xsd:complexType>
>
>         <xsd:complexType name="font_type">
>                 <xsd:simpleContent>
>                         <xsd:extension base="xsd:string">
>                                 <xsd:attribute name="size" 
> type="xsd:integer" use="required"/>
>                         </xsd:extension>
>                 </xsd:simpleContent>
>         </xsd:complexType>
></xsd:schema>
>
>** email.xsd end **
>
>
>The parser options that I am setting are the following:
>- validationScheme = always
>- doSchema = true
>- validationSchemaFullChecking = true
>- doNamespaces = true
>
>The execution of parse() fails and I get these errors:
>
>Error (3,58): Unknown element 'xsd:schema'
>Error (3,58): Attribute '{http://www.w3.org/2000/xmlns/}xsd' is not 
>declared for
>element 'xsd:schema'
>Error (4,28): Unknown element 'xsd:element'
>Error (4,28): Attribute '{}name' is not declared for element 'xsd:element'
>Error (5,20): Unknown element 'xsd:complexType'
>Error (6,18): Unknown element 'xsd:sequence'
>Error (7,49): Unknown element 'xsd:element'
>Error (7,49): Attribute '{}name' is not declared for element 'xsd:element'
>Error (7,49): Attribute '{}type' is not declared for element 'xsd:element'
>Error (8,69): Unknown element 'xsd:element'
>...
>
>What am I doing wrong? Some help would be appreciated.
>
>
>_________________________________________________________________
>Únase con MSN Hotmail al servicio de correo electrónico más grande del 
>mundo. http://www.hotmail.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org