Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict Attribute Value

Status
Not open for further replies.

john2078

Programmer
Oct 20, 2009
1
GB
Hi All,

I have an XMl structure and i am creating XML Schema document for validating xml document.
What i want that for a particular element it should not allow same attribute name.

for example below is the XML structure :

<News>
<Regional>
<Report Region="Asia">
<Title></Title>
<Story></Story>
</Report>
</Regional>
</News>

What i want in Xml Schema how can i restrict that in the "Region" Attribute of elemet <Report> value "Asia" occure only once. It should not allow two <Report> element with the value "Asia" in Region Attribute.

Thanks for the help

-John
 
>for example below is the XML structure :
It cannot be. If there is only one Report tag, how can Region attribute be repeated? If there are more Report tags, it can be multiple through different Report element within the same Regional element; it can be different Regional elements with a single or multiple Report child; it can be different News element if it is not the root. They are all differnt "XML structure". So what do you mean by it being _the_ XML structure. Simplified for showing the generic feature is good, over-simplified is bad.
 
i dont see the logic of having a <regional> node with child nodes containing different regions?

surely:
<regions>
<region name="asia">
<reports>...
</region>
<region name="americas">
....
</region>
<region name="asis">oh dear we dont want this one</region>
</regions>
would be more logical.

sorry i am useless at transforms or schemas (i am keen to learn) but i have adopted xml as my preferred data format for the last 4 years or so. i think i might be reading posts in this forum more than i post, thanks in advance
 
[0] Ok, mrmovie, not everybody is as keen as you "to learn" -you're just being modest in this case,- including possibly the op. As long-time members of the sites, I think you and I have seen enough different kinds of posters. But since you intervene, I could voluntarily do my part.

[1] But that is not to be taken for granted. What is more natural to conceive a document like this. (I create out of BBC News page, for instance.)
[tt]
<News>
<Regionals>
<Report Region="Asia">
<Title>N Korea human rights 'abysmal'</Title>
<Story>A UN envoy criticises the rights situation in North Korea as "abysmal", saying a third of the population was going hungry...</Story>
</Report>
<Report Region="Asia">
<Title>Thai king makes public appearance</Title>
<Story>Thailand's King Bhumibol makes his first public appearance since being admitted to hospital more than a month ago...</Story>
</Report>
<!-- etc etc for all the Regions etc... -->
</Regionals>
<!-- other categories -->
</News>
[/tt]
[1.1] It would be awkward to have Title-Story-Title-Story all within the same Report. Again, why not, either?

[2] If I take your suggested structure, the way to make the constraint is to create an xs:unique element within the xs:element for name="Regional". Like this.
[tt]
<xs:element name="Regional" type="RegionalType">
<xs:unique name="RegionKey">
<xs:selector xpath="Report" />
<xs:field xpath="@Region" />
</xs:unique>
</xs:element>
[/tt]
[2.1] I have abstracted all the type definition for the Regional in a global xs:compleType element named "RegionalType". This separation makes the construction cleaner.

[2.3] That construction is [red]not[/red] for my alternative structure illustrated in [1].

[2.4] In any case, I would think people (maybe the op?) can deduce similar construction from the method I've shown. But, it is by experience useless to expect too much from member's initiative and readiness to dealing with any topics.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top