XML Schema Issues

V

vardan

Hi everyone. I have couple problems with xsd file i'm trying to
create.

first question. is it possible to restrict year input to current year?
I mean i don't want to put
<xs:restriction base="xs:integer">
<xs:minInclusive value="1900" />
<xs:maxInclusive value="2007" />
. is there any way to put getdate() or now() type functions.

second question. is it possible to make one of elements required or
optional depending on the value of the previous element? I realize i
can use "choice" indicator with 2 different elements, but may be there
is another way to do it.


thirs question is related to second. Is it possible to restrict the
value of the element to the value of the one of previous elements.
like
<xs:element name="id" minOccurs="1" type="xs:integer" />
....
<xs:element name="anotherId" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<the value of 'anotherId' must be only one of values
entered in 'id' element>
</xs:restriction>
</xs:simpleType>
</xs:element>

sorry, if questions sound stupid. i'm new in xml schema.
may be the only way to fix this issues is to deal with them when
parsing xml docs.
thanks in advance for any help.
 
J

Joe Kesselman

vardan said:
first question. is it possible to restrict year input to current year?

No.

And you probably don't want to do that; you don't want old documents to
become invalid the moment January 1st hits, or to have to release a new
schema.

Do the date check in application code, not the schema.
second question. is it possible to make one of elements required or
optional depending on the value of the previous element?

No, except via choice. Again, you may want to consider doing this in the
application code.
third question is related to second. Is it possible to restrict the
value of the element to the value of the one of previous elements.

See id/idref and key/keyref. I don't think you can specifically restrict
it to "previous", but a ref isn't valid unless its value appears as the
appropriate type elsewhere in the document.

See also past comments here about what schemas are and aren't tuned for.
They are intended to implement higher-level syntax and some basic
type/structure checking, as a "first pass". Nontrivial semantic
constraints will generally have to be implemented in the application code.
 
V

vardan

<?xml version="1.0" encoding="utf-8" ?>
<quote xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<vehicle>
<id>1</id>
<year>2020</year>
</vehicle>
<vehicle>
<id>2</id>
<year>2019</year>
</vehicle>
<driver>
<vehicleId>1</vehicleId>
</driver>
</quote>


Hi guys. i need to put in xml schema that each vehicle/id is unique
and each driver/vehicleid has a corresponding vehicle/id.
I know i have to use key, keyref stuff. but cannot figure out how. i
guess i'm lost in xmlpaths.
thx in advance.
 
J

Joe Kesselman

vardan said:
Hi guys. i need to put in xml schema that each vehicle/id is unique
and each driver/vehicleid has a corresponding vehicle/id.

Declare the vehicle/id as an ID, and the driver/vehicleid as an IDREF.
IDs are only valid if unique, IDREFs are only valid if they have the
same value as an ID.

Or you can do essentially the same thing with keys and keyrefs.

Remember, this only checks for uniqueness within a single document, not
across documents.

Standard pointer to tutorials/articles: http://www.ibm.com/xml
 
V

vardan

thx again. Joe.

I fixed that issue with key and keyref. I had some problems with
xmlpath, but now it's all good.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top