Re: Cannot create a Schema object for an XSD file with the targetNamespace attribute set on an element

Bernd Eckenfels <[email protected]> Thu, 6 Aug 2015 20:41:53 +0200
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <[email protected]>
Hello,

that is interesting, I see targetNamespace in the XML-Schema 1.1 spec
for top level elements and attributes.

http://www.w3.org/TR/xmlschema11-1/

But it is not in the XML Schema.xsd. (only one occurence of
'name="targetNamespace"') on the <schema> element.

http://www.w3.org/2001/XMLSchema.xsd

BTW: top level elements do require a name="" attribute. You have
specified it on the <simpleType> I think thats not correct.

In your case, can you just use the targetNamespace on the schema
element? This is the most common usage as it cannot be mixed anyway.

Gruss
Bernd


 Am Thu, 6 Aug 2015 18:58:22 +0100
schrieb Julian Cromarty <[email protected]>:

> Hi,
> 
> I'm trying to write a schema using the 1.1 schema language and I need
> to be able to set the targetNamespace attribute on some of the
> elements. When I try and create a Validator to validate XML against
> the schema however, I get an instance of XMLSchema11Factory but when I
> pass the XSD file to the factory's newSchema() method I always get the
> following exception:
> 
> s4s-att-not-allowed: Attribute 'targetNamespace" cannot appear in
> element 'element'.
> 
> I've trimmed the XSD down to a minimal test case that reproduces the
> problem:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xs:schema targetNamespace="http://www.foo.com"
> xmlns="http://www.foo.com" xmlns:other="http://www.bar.com"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>   <xs:element targetNamespace="http://www.bar.com">
>     <xs:simpleType name="ans">
>       <xs:restriction base="xs:string"/>
>     </xs:simpleType>
>   </xs:element>
> </xs:schema>
> 
> And here is the code I'm using to try and create the validator
> 
> System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/XML/XMLSchema/v1.1",
> "org.apache.xerces.jaxp.validation.XMLSchema11Factory");
>       SchemaFactory factory =
>           SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");
>       Schema schema =
>           factory.newSchema(new
> StreamSource(ClassLoader.getSystemResourceAsStream("test.xsd")));
>       xmlValidator = schema.newValidator();
> 
> Does anyone have any idea why this isn't working?
> 
> Kind regards,
> 
> Julian
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>