Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Simple Namespace Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Simple Namespace Question" Watch "Simple Namespace Question" New topic

Simple Namespace Question

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
In the two snippets, one is schema and the other is a XML document, shown below, why a new namespace "po" is created in the XML document? The URI for "po" is the same as that of "mh". Can we use "mh" in the XML document? Or can we not to create a namespace in the XML document? Thank you.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
The XML namespace prefix can be choosen as desired. It is just a convenient way that allows us to refer to a namespace without having to write the entire namespace string.
Best wishes!

My free books and tutorials:
Vinay Nath
Ranch Hand

Joined: Jul 06, 2008
Posts: 85
The prefix name you choose to use in the document should be equal to the targetnamespace of the schema which contains the element you are using.

for example, in your case, mh prefix is just for use in schema definition, but po prefix in document is actually linking to targetnamespace and not mh prefix. Its just that both prefix mh and targetnamespace are the same in this case.

so, you cannot use mh as it is defined for use only in the schema definition.

SCDJWS 5.0, SCBCD 5.0, SCWCD 5.0, SCJP 5.0
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Thanks very much for your help.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
Good Day,

An interesting thing. The scope of the prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag. Meaning, after passing the end tag the prefix is gone.
Please have a look at Namespace Scoping.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
I agree. Here's the link:
subject: Simple Namespace Question
jQuery in Action, 3rd edition