Re: Schema Newbie Boxed in a corner . . .

On 28/04/2008, Frank Merrow <fmerrow@qualcomm.com> wrote:
>
>  At 12:20 AM 4/26/2008, Michael Kay wrote:
>
>  Generally, that's not a good way of designing your XML, which explains why
> there is no way of describing your design in XML Schema. It's best to use
> element and attribute names to denote types, and element or attribute values
> to contain instance data.
>  I was afraid that would be the answer . . .
>
>  Unfortunately, the Application is up and running on hundreds of customer
> sites and dependent on the current setup.
>
>  Rolling to something new will complicate things because we have to maintain
> backwards compatibility for systems with old data, but it think having a
> schema to verify additions is important enough we probably will bite the
> bullet and make the change.
>
>  Thanks for confirming my fears.  ;-)

In the mean time you could use xchecker or something similar and do
XPath 2.0 validation (or XSLT etc)

A basic check would be:

//*/matches(local-name(), 'AI[0-9]{8}')

which would just check all element names were 'AI' + 8 digits.  You
can modify the check to return failures:

for $x in //* return
    	if (matches($x/local-name(), 'AI[0-9]{8}')) then 'true'
    	else concat('Element: ', $x/local-name(), ' fails validation')

xchecker will return any item in the sequence that's not "true" as the
failure message, so you have the freedom of the language to return as
much information as you like....

I wrote xchecker in a couple of days a year or so ago with the initial
goal of augmenting XML Schema with XPath 2.0 (in the appinfo element)
but it grew to be a standalone product as well.

So one approach if you have an existing XML Schema is to add the XPath
2.0 checks to the schema within the xs:appinfo element and use the
XCheckerSchemaFactory as the JAXP SchemaFactory.

The other approach is from the command line where you write the XPath
2.0 directly in the "check config" files, or perhaps refer to XSLT 2.0
files (which give a little more flexibility in complex checks).

ymmv.

http://xchecker.sourceforge.net/


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Received on Monday, 28 April 2008 12:02:19 UTC