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

Hi,

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.

Simon

--- 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:complexType>
   <xsd:sequence>
    <xsd:element name="myelement">
	<xsd:complexType>
	 <xsd:sequence/>
	 <xsd:attribute name = "attr1" use = "default" value = "one" type = 
"xsd:string"/>
	 <xsd:attribute name = "attr2" use = "default" value = "two" type = 
"xsd:string"/>
      </xsd:complexType>
     </xsd:element>
    </xsd:sequence>
   </xsd:complexType>
</xsd:element>
</xsd:schema>

--- XML Document ---

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

--- Code ---

DOMParser parser = new DOMParser();

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

  parser.parse(filename);
}
catch etc. etc.

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


Mime
View raw message