473,399 Members | 3,038 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,399 software developers and data experts.

Restricting a type by using an attribute on the element using the type?


This is a modelling style question, I think.

I am working with a somewhat XML Schema-like formalism which defines
the structure of an instance document, supplying a number of built-in
types (a very light-weight Schema).

One of the built-in types is called "ref", and its defined values are
location paths to other elements in the instance document.

An example:

<spec xmlns:types="urn:example:mytypes.1">
<e name="top">
<e name="a" type="types:int" minOccurs="0"/>
<e name="elts">
<e name="e1" type="types:int"/>
<e name="e2" type="types:string"/>
<e name="e3" type="types:ref"/>
</e>
</e>
</spec>

This is a valid instance of the above:

<top>
<a>3</a>
<elts>
<e1>1</e1>
<e2>earth</e2>
<e3>/top/a</e3>
</elts>
</top>

My question deals with how best to specify additional parameters of
the
"ref" type. One thing I'd like to be able to say is "the element
pointed
to by the location path must actually exist", respectively "does not
have to exist" (elements can be created and destroyed in runtime).

This can be expressed with an attribute to the <e/element:

<e name="e3" type="types:ref" must_exist="true"/>

My question is: is this a proper way of doing it? It seems slightly
peculiar to supply the general </eelement with an attribute which
will only be valid for one particular value of another attribute.

(Of course I can make a "types:ref_must_exists" type, but there will
be more complicated ways to restrict the type.)

Feb 9 '07 #1
2 1564
Hi Arndt,

"Arndt Jonasson" <ar************@gmail.comwrites:
My question deals with how best to specify additional parameters of
the
"ref" type. One thing I'd like to be able to say is "the element
pointed
to by the location path must actually exist", respectively "does not
have to exist" (elements can be created and destroyed in runtime).

This can be expressed with an attribute to the <e/element:

<e name="e3" type="types:ref" must_exist="true"/>

My question is: is this a proper way of doing it? It seems slightly
peculiar to supply the general </eelement with an attribute which
will only be valid for one particular value of another attribute.

(Of course I can make a "types:ref_must_exists" type, but there will
be more complicated ways to restrict the type.)
Your must_exist attribute is changing the ref type, not the element
so it naturally belongs to the type definition. XML Schema does this
by allowing you to create a new type that restrict the original. In
your case it could look like so:
<t name="my_t">
<r base="types:ref" must_exist="true"/>
</t>

<e name="e3" type="my_t"/>

You could have several attributes/elements like must_exist that
change different aspects of different types.
hth,
-boris

--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding
Feb 9 '07 #2
On Feb 9, 6:04 pm, Boris Kolpackov <b...@codesynthesis.comwrote:
Hi Arndt,

"Arndt Jonasson" <arndt.jonas...@gmail.comwrites:
My question deals with how best to specify additional parameters of
the
"ref" type. One thing I'd like to be able to say is "the element
pointed
to by the location path must actually exist", respectively "does not
have to exist" (elements can be created and destroyed in runtime).
This can be expressed with an attribute to the <e/element:
<e name="e3" type="types:ref" must_exist="true"/>
My question is: is this a proper way of doing it? It seems slightly
peculiar to supply the general </eelement with an attribute which
will only be valid for one particular value of another attribute.
(Of course I can make a "types:ref_must_exists" type, but there will
be more complicated ways to restrict the type.)

Your must_exist attribute is changing the ref type, not the element
so it naturally belongs to the type definition. XML Schema does this
by allowing you to create a new type that restrict the original. In
your case it could look like so:

<t name="my_t">
<r base="types:ref" must_exist="true"/>
</t>

<e name="e3" type="my_t"/>

You could have several attributes/elements like must_exist that
change different aspects of different types.
Creating a subtype feels conceptually cleaner, but since this is text
that humans are supposed to write, I think the users may feel that it
gets unnecessarily cluttered with having to create subtypes which
are only used once.

Thank you for your answer.

Feb 12 '07 #3

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

Similar topics

3
by: Victor | last post by:
Hi, I have some sample XML and an XSD below I have written. The XSD almost does what I want. What I need is some way of enforcing that AT LEAST TWO of the attributes "TestAttribute" are "X". ...
3
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of...
31
by: xah | last post by:
what's the pro and con of using <script language="javascript"> vs <script type="text/javascript"> Xah xah@xahlee.org ∑ http://xahlee.org/
0
by: Douha | last post by:
Hi all, I have an XML file where all to elements for the data are contained in CDATA sections. I have a schema created that is working right now although it is pretty dumbed down. I have a need...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
3
by: Lord0 | last post by:
I am trying to implement variable content containers using an abstract type and type substitution. My schema is as follows: <?xml version="1.0" encoding="UTF-8"?> <schema...
5
by: mknoll217 | last post by:
I am a newbie at XML. I have been given an xml document that I need to write the schema for, for a class assignment. The xml given to me is <?xml version="1.0"?> <Vendors> <Vendor> ...
5
by: =?Utf-8?B?RG9u?= | last post by:
Hi I am trying to put value restrictions on certain elements in an xml file using a schema file. The syntax in my schema file looks like the following <xs:element name="AXYZMachines"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.