There was an enhancement in XML Schema 1.1 which allows targetNamespace on <xs:element> but I recall that it only applies to (and is only allowed on) local element declarations [1].
[1] http://www.w3.org/TR/xmlschema11-1/#dcl.elt.local Michael Glavassevich XML Technologies and WAS Development IBM Toronto Lab E-mail: mrgla...@ca.ibm.com E-mail: mrgla...@apache.org jeff.gr...@gmail.com wrote on 08/06/2015 06:09:23 PM: > I am mainly familiar with XML Schema 1.0, so it's possible my > assertions below have been supplanted in 1.1. > > The purpose of a schema is to declare the contents of a single > namespace, the target namespace, which is declared on the 'schema' element. > > Constructs of another namespace cannot be declared in this schema; > they can only be referenced, using qualified names. > > So <element name="xyz" ...> declares an element in the target namespace. > <element ref="other:abc" ...> refers to a global element in the > namespace declared to correspond to the prefix "other". > > Jeff > > On Thu, Aug 6, 2015 at 2:59 PM, Julian Cromarty <julian.croma...@gmail.com > > wrote: > Hi, > > Unfortunately I can't just use the targetNamespace in the schema > element. There are top-level elements of the global targetNamespace > and also top level elements from another namespace. Both of these > can contain elements from both namespaces, thus the need to refer to > another namespace at the element level. It's a strange requirement, > I admit. That said, if element-level targetNamespaces aren't for > referring to namespaces other than the targetNamespace specified in > the schema element, what are they for? > > As for the top-level elements requiring a name, I spotted that > mistake after sending the email. It's just a typo from reducing the > xsd to a minimal test case. That said, it still reproduces the > problem even when the top-level element is correctly given a name. > Cheers, > Julian > > On Thu, Aug 6, 2015 at 7:41 PM, Bernd Eckenfels <e...@zusammenkunft.net > > wrote: > 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 <julian.croma...@gmail.com>: > > > 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: j-users-unsubscr...@xerces.apache.org > > For additional commands, e-mail: j-users-h...@xerces.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org For additional commands, e-mail: j-users-h...@xerces.apache.org