Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Same element name but different content.

 
Karthik Jayaraman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been blowing my mind on this for a while now. Let me try to explain the best I can.
XML Schemas have this advantage that multiple elements with the same name and different content can be present.
Lets look at it at a different aspect. In DTDs, element names, attribute names should be unique throughout the document. But in schemas, the element names are in the element symbol space, attributes in the attribute symbol space and types in the type symbol space. So, we can have an element, attribute and a type with the same name
OK. thats pretty clear.
Now look at this schema snippet
<complexType>
<sequence>
<element name="title" type="string" />
<element name="title" type="string" />
</sequence>
</complexType>
This is a legal schema where we define two elements in a sequence with a same name and they can have different content in the instance document
[Question 1: Why would anyone want to do this? Can anyone help me out with a practical example for this.]
Secondly if the types were different, the schema is illegal. Ok. Lets look at another way of it. I have two types booktype and magazine type. both have title elements within them.
In the namespace, isnt there a name conflict for the two title elements. No, because we can have the elementFormDefault to be "unqualified". This way we can say that only the root elements need to be in the namespace and the local elements would indirectly be associated with the namespace through the parent element.
Fine, pretty understandable.
[Qustion 2: what if the elementFormDefault was "qualified" would it be illegal?
Question 3: If elementFormDefault was "unqualified" and the type of the elements were different, would it be illegal?]
Please help. Thx in advance.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic