[jdom-interest] XML Schema problem

Moritz Petersen mail at moritzpetersen.de
Wed Mar 25 14:39:08 PDT 2009


Hello everyone,

I've run into a strange problem. In my project I experimented a bit  
with XML Schema validation. I use 4 approaches to generate XML and XML  
Schema documents: Files (both documents exist as actual XML files),  
JDOM (both documents get generated with JDOM), dom4j and XOM.

Why am I posting to this list? I started development on a Windows  
machine. All my tests run smoothly on that machine. When installing  
the same project on my old Mac (PowerBook G4, Mac OS X 10.5.6, java  
version "1.5.0_16"), both tests for JDOM and dom4j fail with the same  
error:

org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid  
attribute value for 'type' in element 'element'. Recorded reason:  
UndeclaredPrefix: Cannot resolve 'xs:decimal' as a QName: the prefix  
'xs' is not declared.

The test code is the same for each test:

     protected void assertXsdValid(Source xsdSource, InputSource  
xmlInputSource) throws SAXException, ParserConfigurationException,  
IOException {
         isValid = true;
         SchemaFactory sf =  
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
         sf.setErrorHandler(myErrorHandler);
         Schema schema = sf.newSchema(xsdSource); // <<--- Here it  
fails!!
         DocumentBuilderFactory dbf =  
DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(true);
         dbf.setSchema(schema);
         DocumentBuilder db = dbf.newDocumentBuilder();
         db.setErrorHandler(myErrorHandler);
         db.parse(xmlInputSource); // sets the isValid field to false  
if validation fails
         assertTrue(isValid);
     }

The strange thing is, that if I copy the JDOM generated XSD file into  
the XSD file of the "file test" (see above), then the "file test" does  
not fail. This is how the XSD file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://some.org/metamodel"  
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema 
">
   <xs:element name="system">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="name" type="xs:string"/>
         <xs:element name="vendor" type="xs:string"/>
         <xs:element name="version" type="xs:decimal"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
</xs:schema>

I can't help but guessing that this might be some Mac related issue,  
but I cannot figure out what it might be. Maybe someone in this list  
can help me out.

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20090325/2bf013cd/attachment.htm


More information about the jdom-interest mailing list