• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Condition on attributes : Can an element has same attribute from two different namespaces

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I read in the spec that, attributes can not be repeated in an element declaration. Based on this, I have few questions.

1) Can an element has same attribute taken from different namespace.

tns and xs belong are prefixes of two different namespaces


tns, xs are prefixes of same namepace


First attribute belongs to default namespace and xs is the prefix of the same namespace as that of default


I know that first example is a valid one, second is invalid, but can not understand the third one. Can some body throw some light on this ?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to have fallen into the common error of believing that the prefix is the important part of the namespace. It isn't. The namespace URI is what defines the namespace, and the prefix is just a meaningless string for the convenience of XML authors.

In the first example you have a "{http://www.example1.org/xml/sample}category" attribute and then you have a "{http://www.example2.org/xml/sample}category" attribute. These have different names.

In the second example you have two "{http://www.example.org/xml/sample}category" attributes. They have the same name.

And in the third example you also have two "{http://www.example.org/xml/sample}category" attributes, which have the same name.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<myname:products
xmlns:myname="Jimmy"
xmlns:yourname="Rajani"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/xml/sample Sample.xsd ">

<myname:product

myname:category="books"
yourname:category="printed materials">

</myname:product>

</myname:products>


This example shows two different category attributes, each belongs to a different namespace. An XML parser will read this as:


<Jimmy:products
xmlns:myname="Jimmy"
xmlns:yourname="Rajani"
xmlns:xsi="XMLSchema-instance"

XMLSchema-instance:schemaLocation="http://www.example.org/xml/sample Sample.xsd ">

<Jimmy:product

Jimmy:category="books"
Rajani:category="printed materials">

</Jimmy:product>

</Jimmy:products>



 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>I know that first example is a valid one, second is invalid,...
To be more precise, the first example is well-formed, the second is not. Despite the apparent of having some xsd schema referred in the root, it has nothing to do with the validation which has never begun to begin.

ps: As to the second figurative explanation starting with xmlns:yourname etc... and ending with Rajani:category etc..., on the face of it reverting namespace uri to namespace prefix: I can see what is intended to convery, but, it risks to distort the issue with more confusion. But, again, I see what is intended to convey and I have no problem with the hidden message.
 
Men call me Jim. Women look past me to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic