[xsd-users] How to determine if the xsd:QName is qualified?

Boris Kolpackov boris at codesynthesis.com
Mon Jun 7 10:02:23 EDT 2010


Hi Vladimir,

Vladimir Vasilyev <Vladimir.Vasilyev at samtec.de> writes:

> When I use a qualified name in my xsd/xml, i want to be able to find out
> if the name is qualified or not. As far as i found out there is a
> special function for that qname::qualified.
> 
> Somehow in the following example i get that the "QName" is always
> qualified (from my point of view it is not qualified in the supplied
> xml):
> 
> XSD:
> <?xml version="1.0"?>
> <xsd:schema targetNamespace="MyNamespace"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:mns="MyNamespace"
> elementFormDefault="qualified" >
>   <xsd:complexType name="person">
>     <xsd:sequence>
>       <xsd:element name="name" type="xsd:string"/>
>     </xsd:sequence>
>     <xsd:attribute name="QName" type="xsd:QName"/>
>   </xsd:complexType>
>   <xsd:element name="supermen" type="mns:person"/>
> </xsd:schema>
> 
> XML:
> <?xml version="1.0"?>
> <supermen xmlns="MyNamespace"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="MyNamespace supermen.xsd"
> QName="NCName">
>     <name>John Doe</name>
> </supermen>

The "NCName" value is qualified in the above XML file because you 
have a default namespace declaration (xmlns="MyNamespace") which
makes all names without an explicit namespace prefix end up in 
this namespace. If, however, we change the above XML like below,
then the "NCName" value will be unqualified:

<p:supermen xmlns:p="MyNamespace"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="MyNamespace supermen.xsd"
  QName="NCName">
    <p:name>John Doe</p:name>
</p:supermen>

Boris



More information about the xsd-users mailing list