I am trying to grasp the technical side of working with the default namespace, when starting with a schema (developing one) and considering a realistic and correct corresponding XML file.
I am using Oxygen to design the schema.
Ideally, I would like that the user of the XML files do not have to deal with the default namespace (because they are painful, when trying to use XPath on documents which have declared the default namespace). However, from what I read so far, it seems that is not possible?
My example schema looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/"
xmlns="http://www.example.com/">
<xs:element name="QueryResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="Result"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Result">
<xs:complexType>
<xs:sequence>
<xs:element ref="Patient"/>
</xs:sequence>
<xs:attribute name="type" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="VisitNumber" type="xs:string"/>
<xs:element name="Demographics">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="firstNames" type="xs:string"/>
<xs:element minOccurs="1" maxOccurs="1" name="surname" type="xs:string"/>
<xs:element minOccurs="1" maxOccurs="1" name="dateOfBirth" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Patient">
<xs:complexType>
<xs:sequence>
<xs:element ref="Demographics"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and oxygen generates an example XML which looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<QueryResponse xmlns="http://www.example.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com/ file:/home/me/simplifiedResponse.xsd">
<Result>
<Patient>
<Demographics>
<firstNames xmlns="">firstNames0</firstNames>
<surname xmlns="">surname0</surname>
<dateOfBirth xmlns="">2006-05-04T18:13:51.0Z</dateOfBirth>
</Demographics>
</Patient>
</Result>
</QueryResponse>
My question is:
Because the elements in question are not in any namespace. They cannot use an alternative prefix, because unqualified expanded names can only be represented by unprefixed names. But they are children of elements using a non-empty default namespace. So the only way they can appear in the document is by clearing the default namespace declaration.
Stop declaring the elements as not being in any namespace. The simplest approach is to add elementFormDefault="qualified"
to the schema element.
Yes.
Omit the targetNamespace
attribute on xs:schema
.
Google is your friend.