xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Tyler" <tylersi...@hotmail.com>
Subject XML Schema validation and default attributes
Date Fri, 05 Jan 2001 15:31:02 GMT


I've been trying to use Xerces-j 1.2.3 with XML Schemas and I'm having a few 
problems. Sorry if this has been covered before but I couldn't find anything 
in the archives.

I'm trying to read some XML into a DOM validating it as I go. I would like 
the DOM to include any attribute defaults that are set in the schema. I'm 
having two problems:

1. Validation doesn't seem to occur. I can enter invalid elements and the 
parser seems to be happy with it. Tools like XMLSpy complain about the 
invalid element.

2. When I look at the DOM that was produced none of the attribute defaults 
get inserted, only attributes that exist in the original document.

Included below is an example XML document, XML Schema and a source snippet 
of the parser options I'm using. I know the examples use the "2000/10" 
standard but this is for XMLSpy, repplacing with "1999" makes no difference.

Thanks for any help. Could you reply directly as well as to the list.


--- XML Schema ---

<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
<xsd:element name="attrtest">
    <xsd:element name="myelement">
	 <xsd:attribute name = "attr1" use = "default" value = "one" type = 
	 <xsd:attribute name = "attr2" use = "default" value = "two" type = 

--- XML Document ---

<?xml version="1.0" encoding="UTF-8"?>
<attrtest xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 
  <myelement attr1="test"/>

--- Code ---

DOMParser parser = new DOMParser();

  parser.setFeature("http://xml.org/sax/features/validation",true );

catch etc. etc.

Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

View raw message