• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Namespace Question

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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!
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for your help.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic