473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Applying Restrictions to XML Attributes

Hi,

I'm still learning, so apologies if this is trivial...

Given the following XML snippet:

<Record>
<foo id="a">... </foo>
<foo id="b">....</foo>
<foo id="c">.....</foo>
</Record>

Is it possible to create an xsd file that enforces that within the
<Recordblock there exists exactly three foo tags each containing a
different id value (from the enum a, b, and c )? My attempts to
define complexTypes for each of the foo elements has resulted in a
validation error indicating that the element foo needs to be defined
with a consistent type.

Feb 1 '08 #1
2 2308

mn*******@gmail.com <mn*******@gmail.comwrote in
<f0**********************************@d70g2000hsb. googlegroups.com>:
I'm still learning, so apologies if this is trivial...
W3C's XML Schema Primer is a good, solid tutorial, if a bit
on the chewy side.
<Record>
<foo id="a">... </foo>
<foo id="b">....</foo>
<foo id="c">.....</foo>
</Record>

Is it possible to create an xsd file that enforces that
within the <Recordblock there exists exactly three foo
tags each containing a different id value (from the enum
a, b, and c )?
It is possible.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element ref="Record"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Record">
<xs:complexType>
<xs:sequence>
<xs:element ref="foo" minOccurs="3" maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="abc">
<xs:selector xpath="foo"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
<xs:element name="foo">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="id" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:attribute name="id">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(a|b|c)"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>

Note that the fact that it is, indeed, possible doesn't yet
mean it's a good idea. My knee-jerk reaction would be to
redefine foo as three separate elements (foo-a, foo-b,
foo-c or something). Keep your grammars as simple as
possible, or you'll be in for a nasty surpise when you run
into unavoidable limitations of XML Schemata.

--
<>There is no phenotype</>
Feb 1 '08 #2
On 1 Feb, 10:23, Pavel Lepin <p.le...@ctncorp.comwrote:
use...@tech-know-ware.com <use...@tech-know-ware.comwrote
in
<8f2742d7-79d0-4c33-bb39-3dcfb92d3...@e4g2000hsg.googlegroups.com>:
Having thought about it for some five-ten minutes I tend to
agree in general. Defining attributes separately and
referring to them in element definitions should probably be
avoided, unless there's a very good reason for this (like,
some sort of meta-information present on many different
elements: but in that case it makes perfect sense to
namespace the attribute as well, so there).
Makes sense to me. Nice to know my ramblings occasionally make sense!

Cheers,

Pete Cordell
Codalogic
Visit http://www.codalogic.com/lmx/ for XML C++ data binding
Feb 1 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ruthless | last post by:
hello. I've got a problem - can I do any restrictions for my attributes? I found how to restrict elements and was trying to use them with my attributes e.g. <person sex="F"> sex can be anly...
2
by: Victor | last post by:
I have a Schema with some elements which are "types" or objects, and some elements which correspond to instances of the types. How can I specify that a <locationInstance> must have an attribute...
2
by: Shailendra Batham | last post by:
Hello Gurus, I want to put some restrictions on my attribute tag in my XML Schema, anyone out there have any idea how to do that. here is my XML and the XML Schema <?xml version="1.0"...
8
by: KathyB | last post by:
Please tell me where I'm going wrong on the marked lines***. The code is fine to that point. I've only used this code to populate dropdownlists using databind to the control. Here, I just need to...
7
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
3
by: Merennulli | last post by:
My problem child: <asp:dropdownlist id="ddlLimit" tabIndex="6" runat="server" EnableViewState="False" CssClass="query"> <asp:ListItem Value="100" Selected="True">100</asp:ListItem>...
0
by: =?Utf-8?B?R3JlZyBDbGFyaw==?= | last post by:
I have a complex object created and filled with data for display in a property Grid. In many cases I need the data to be ranged, formatted and a 'units' string to be appended. To this end, I...
8
by: Mort Strom | last post by:
Right now the header of my master page contains all of the CSS styles for all of the pages that might be loaded in my ContentPlaceHolder. The problem is that my <styletag is getting too large to...
3
by: Marc Hebert | last post by:
I'm trying to figure out if something is possible to specify and constrain using a schema. I'll explain using an example. sample xml: <person name="John" age="32"/> <person name="Julie"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.