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:
- Why does Oxygen generate child elements with empty xmlns attributes ?
- How can I BEST avoid this?
- Is it possible to create a schema which can correctly describe and validate an XML document which, rather, has no declared namespace (default or otherwise).
- If the answer to (c) is, 'yes', how would you modify my schema example
- What is a really good document to explain all this in a bit more depth, but be readable at the same time (i.e., I don't find documents at http://www.w3.org/XML/ at all easy to understand or read).