Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Adding new attributes to schema

Reply
Thread Tools

Adding new attributes to schema

 
 
craig.wagner@gmail.com
Guest
Posts: n/a
 
      02-07-2006
I have a situation where I need to carry additional information in an
XML Schema. What I've found to appear to work is doing something like
the following:

<xs:schema xmlnss=" http://www.w3.org/2001/XMLSchema"
xmlnsx="http://www.mycompany.com">
<xs:complexType name="SomeType">
<xs:sequence>
<xs:element name="AccountNumber" type="xs:int"
xx:errorAction="fail"/>
<xs:element name="AccountName" type="xs:string"
xx:errorAction="truncate" xx:length="25"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

This appears to work just fine. One thing I'm wondering though is how,
or if it's possible, to ensure that the xx: stuff that gets put in
falls within the rules we define. For example, the only valid
attributes are xx:errorAction and xx:length, xx:errorAction must be
part of a finite set (null, fail, truncate), and xx:length must be > 0.

We could live without doing this if it's going to be an excessive
amount of work, but if it's reasonable to do so it'll make the app more
bullet-proof.

Pointers or thoughts would be appreciated.

 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      02-07-2006
You can use a Schematron schema to check that your XML Schema follows
the desired constraints. Here it is a working Schematron schema based
on your example:

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron"
xmlnsx="http://www.mycompany.com">
<sch:ns prefix="xx" uri="http://www.mycompany.com"/>
<schattern name="Check xx: attributes">
<sch:rule context="*[@xx:*]">
<sch:assert test="not(@xx:*[local-name()!='errorAction' and
local-name()!='length'])"> The
possible xx attributes are errorAction and length.
</sch:assert>
</sch:rule>
</schattern>
<schattern name="Check xx:errorAction">
<sch:rule context="*[@xx:errorAction]">
<sch:assert
test="@xx:errorAction='null' or @xx:errorAction='fail' or
@xx:errorAction='truncate'">
Possible values for xx:errorAction are null, fail or truncate.
</sch:assert>
</sch:rule>
</schattern>
<schattern name="Check xx:length">
<sch:rule context="*[@xx:length]">
<sch:assert test="@xx:length>0"> The xx:length attribute must be
greater than zero.
</sch:assert>
</sch:rule>
</schattern>
</sch:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

 
Reply With Quote
 
 
 
 
Henry S. Thompson
Guest
Posts: n/a
 
      02-07-2006
craig.wagner writes:

> I have a situation where I need to carry additional information in an
> XML Schema. What I've found to appear to work is doing something like
> the following:
>
> <xs:schema xmlnss=" http://www.w3.org/2001/XMLSchema"
> xmlnsx="http://www.mycompany.com">
> . . .


> <xs:element name="AccountName" type="xs:string"
> xx:errorAction="truncate" xx:length="25"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
> This appears to work just fine. One thing I'm wondering though is how,
> or if it's possible, to ensure that the xx: stuff that gets put in
> falls within the rules we define. For example, the only valid
> attributes are xx:errorAction and xx:length, xx:errorAction must be
> part of a finite set (null, fail, truncate), and xx:length must be > 0.


A schema document is an XML document like any other, and most schema
validators check the schema documents they are handed with the schema
for schema documents. This uses lax attribute wildcards in virtually
all its type definitions, which is why your schema document (above) is
OK. This means that to get validation of your added attributes, just
define a schema for your namespace with appropriate top-level
attribute declarations, e.g.

<xs:attribute name="errorAction">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="null"/>
<xs:enumeration value="fail"/>
<xs:enumeration value="truncate"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>

and add

xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mycompany.com [URI for doc. defining schema]"

to the original schema document.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
craig.wagner@gmail.com
Guest
Posts: n/a
 
      02-08-2006
Thank you for your suggestions, but I'm still having some trouble.

I created a separate XSD as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.xx.com">
<xs:attribute name="errorAction">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="null"/>
<xs:enumeration value="fail"/>
<xs:enumeration value="trunc"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>

I then changed my original schema as follows:

<xs:schema
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlnsx="http://www.xx.com"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xx.com C:\xx.XSD">

So far everything seems okay. But if I declare an element as follows:

xs:element name="AccountNumber" xx:errorAction="fail" xx:foo="bar">

It still tells me the document is valid (even though xx:foo shouldn't
be).

Still kind of a neophyte to this stuff, so I can't figure out what it
is I'm doing or not doing here.

 
Reply With Quote
 
Henry S. Thompson
Guest
Posts: n/a
 
      02-10-2006
craig.wagner writes:

> It still tells me the document is valid (even though xx:foo shouldn't
> be).


'It'? What validator are you using, invoked in what way?

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to xml schema - does the dtd/schema validation happens always ? pramodr XML 3 04-05-2009 12:10 PM
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Problem with schema-validation and property "http://apache.org/xml/properties/schema/external-schemaLocation" Markus Java 1 11-23-2005 02:41 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
[ASL] the Active Schema Language : a new schema technology Philippe Poulard XML 0 03-21-2005 09:23 AM



Advertisments