Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML default namespace issue

Suppose I have the following XML schema file and the following XML document file. I have two questions,

  1. Since there is no target name space specified in XML Schema file, what namespace will Information element in?

  2. In the XML document file, when using Information, which namespace does it belong to? Please notice in this case, I do not refer to XML Schema file from the XML document file.

XML Schema file:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Information" type="xs:string"/>
</xs:schema>

XML document file:

<?xml version="1.0" encoding="utf-8"?>
<Information>Hello XML</Information>

thanks in advance, George

like image 680
George2 Avatar asked Apr 16 '09 09:04

George2


2 Answers

The Information element will be in no namespace. To put it in a default namespace you would have to specify that namespace in the tag.

<Information xmlns="http://www.mydefaultnamespace.com">

From an Oracle article:

No Namespace

No namespace exists when there is no default namespace in scope. A {default namespace} is one that is declared explicitly using xmlns. When a {default namespace} has not been >declared at all using xmlns, it is incorrect to say that the elements are in {default >namespace}. In such cases, we say that the elements are in {no namespace}. {no namespace} >also applies when an already declared {default namespace} is undeclared.

Here's a pretty comprehensive namespace resource:

XML Namespaces FAQ

like image 103
dommer Avatar answered Oct 05 '22 06:10

dommer


Why are you defining a Schema for no target? It does not make sense.

like image 29
leppie Avatar answered Oct 05 '22 08:10

leppie