5

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

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

4 Comments

@dommer, I think in my case, Information element in XML schema file is defined in no namespace. Another question, how will we refer such element (in no namespace) in XML document file?
I'm not sure you can refer to it explicitly. What would you refer to?There's no namespace. I think you'd have to assign a default namespace to be able to refer to anything explicitly - but I'm prepared to be proven wrong.
@null, I am very interested in how to define default namespace in XML schema and default namespace in XML document file. Could you show us a simple samples please?
@dommer Can you please help me with this question: stackoverflow.com/questions/26699855/… ? It says java but I think it is valid for any xml file..
1

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

4 Comments

@leppie, 1. do you mean if there is no target namespace defined in schema file, there is no way to refer such defined scehma elements in XML document? 2. if we do not specify target namespace in XML schema file, what namespace will defined element in -- in default namespace or in no namespace?
Hi George :) 1. Yes. 2. Nothing, it's just meaningless text in verbose brackets. It depends what you are using to read the XML. XML is useless with schema. You could however predefine the default schema in your given XML validating reader, and that would avoid you having to define the default namespace. Not giving a namespace is almost like anonymous classes in C#, in a lexical sense.
Cool answer, leppie! I am interested in -- "You could however predefine the default schema in your given XML validating reader, and that would avoid you having to define the default namespace.", you mean there is a way to define default schema in validating reader other than in XML document itself by using xmlns? If yes, could you show me a sample please? 2. "Not giving a namespace is almost like anonymous classes in C#" -- you mean not specifying target namespace (continue)
of XML schema file, or you mean not defining namespace in XML document?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.