Re: XML namespaces

Hi Benjamin,

> Is it absolutely essential to qualify all elements in a document with the
> namespace prefix even when all the elements are from the same namespace?
> I have a XML file that looks approximately like
> <SupplierRecord xmlns="http://mycompany/schemas/supplier1";>
> <Header>.....</Header>
> <Body>....</Body>
> </Supplier Record>
> When i try to validate this against the schema, it throws errors for every
> single element saying that it couldnt locate the namespace. So i generated
> a
> instance from the schema and found that it creates a file that looks like
> this
> <ns0:SupplierRecord xmlns:ns0="http://mycompany/schemas/supplier1";>
> <Header>.....</Header>
> <Body>....</Body>
> </ns0:Supplier Record>
> When i manually put the ns0: into my original document , it validated
> without a complaint
> I cant understand it .. why would it matter if there is a prefix or not
> when
> all the elements are in the same schema?

Ahh, now I understand you. Your problem is indeed the
elementQualifiedDefault. See, you are right that all elements are defined in
the same schema. However, XSD has the concept of qualified and unqualified
elements, which means that qualified elements are defined to be in the
targetNamespace of the XSD, while unqualified elements are in the global
unnamed namespace ("").

By default, XSD uses elementQualifiedDefault="unqualified", which means that
global elements (such as the root element) are qualified always, while other
elements are unqualified. That's what leads to your second example document.

What you want is to create your XSD with
elementQualifiedDefault="qualified", which will ensure that all elements are
required to be qualified (that is, belong to the targetNamespace)
independent of where they are located. This would lead you to:

<ns0:SupplierRecord xmlns:ns0="http://mycompany/schemas/supplier1";>
</ns0:Supplier Record>

which is equivalent xml-wise to:

<SupplierRecord xmlns="http://mycompany/schemas/supplier1";>
</Supplier Record>

BTW, it doesn't matter that the prefix above is ns0 or MyPrefix; it's the
same as far as XML namespace is concerned as long as the prefix matches to
the correct namespace.

Tomas Restrepo


Relevant Pages

  • Re: Map Error "btm1044: input validation error"
    ... My solution would be to set the root element to qualified and the child ... How do I force usage of of the prefix ... and all elements under it qualify for the namespace. ...
  • Re: XML namespaces
    ... namespace prefix even when all the elements are from the same namespace? ... When i try to validate this against the schema, ... XSD has the concept of qualified and unqualified ...
  • Re: Do you recognise this schema?
    ... The author of the XML decide which prefix he would like to ... use for each namespace. ... I prefer xsd, but ... ...
  • Re: SelectSingleNode with namespaces
    ... the namespace is either declared in the root element or no namespace ... is declared at all (and no xsd is referenced). ... // set up namespace manager and prefix as ...
  • Re: master / detail datagrid...
    ... Macromedia uses their prefix in the exact same way an XML ... A patent on the other hand can be obtained but unlike the paltry ... and an XML Namespace is the equivalent of a short musical ...