Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2010, 03:10 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Rename global entities in an XML Schema

Please, please, please tell me I'm over thinking this.

I'm using OxygenXML 11.2 which uses Saxon PE, HE, or EE for transformations.

I have a set of schemas to define the structure of some XML I'm developing. There are 3 schemas in the set, one is considered the 'base' schema and it imports the next, which in turn imports the last. Each schema has it's own namespace definition. I tend to write my schemas using global entities (elements, attributes, types, groups) and access them through references.

The problem I have is a customer has come along and want to generate Java code from the schemas using something called Castor. I don't know much about Castor, except that it generates Java classes based on global entities defined in the schema.
Castor apparently does not understand namespaces very well and some of the element names I've chosen are already in use by the customer in other XML areas (elements like 'table', and types like 'alpha-numeric') which is why I used namespaces in the first place.

So the customer wants me to rename all my elements to have a unique name. I don't really want to do this as it would affect all my XSLT code, XML files and schemas. So I told them I would use a script to generate custom schemas for them from my schemas and prefix all global entities with a string of their choosing (they chose 'nms_' as they are a network management system) and deliver these schemas to them to use with Castor.

So I did pretty well with renaming elements using a basic recursive 'copy' template as laid out in the XSLT 2.0 3rd edition by Mr. Kay. I've got a few templates to override the straight copy so I can insert the new element names where needed. I leave all non-global element names alone and only change the global names and the references to them.

I suspect attributes and groups will be just as easy.

It starts getting tricky with the types. To do these I need to locate the global types, then search through the sheet to find anything that is referencing it and change the names.

I also need to know if a type is referencing a definition in another namespace and deal with that correctly. Not impossible, but it sounds like a lot of code to me.

As I said, I hope I'm over thinking this and there is really a simpler way to do this.

Please?

Thanks,

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old April 14th, 2010, 03:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I remember looking at Castor a few years ago and noticing that it didn't do namespaces very well. Your client might be better off with a better Java data binding tool - there are quite a few to choose from. (I don't expect they can be persuaded to drop the idea of data binding technology entirely.)

Transforming XSD schema documents isn't straightforward, as you have observed; though it's easier if you only have to deal with three specific schema documents, rather than anything that anyone chooses to write. For example, you might not have to deal with all combinations of elementFormDefault and attributeFormDefault, not to mention the "form" attribute which I'm not sure I've ever seen in a real life schema.

One solution might be to use Saxon to export the schema into an SCM file, which collects all the schema components into one place and represents them in a systematic way, making it more amenable to processing (it's still XML). Unfortunately though there's no reverse transformation from SCM back to XSD.

But actually, I'm not sure why the types are causing you greater problems than any other components. I can't see why references to types are more difficult than, say, references to attribute groups or references to element declarations. I would have expected exactly the same renaming logic to apply to all components and component references.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
mphare (April 14th, 2010)
 
Old April 14th, 2010, 05:05 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks, Michael.

I have another group consuming the schemas for Java class data binding, I believe they use XMLBeans and they do not have a problem with the namespaces. We tried to get the other group to switch, but they have Castor too ingrained in their process to switch at this point.

You may be right. Type may be no more complex than the other entities. I may just need to spend some more time with it.

Thanks again!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
Any tool to validate the length of each xml attribute against an xml schema LeoMathew XML 6 December 8th, 2009 05:02 AM
Any tool to validate the length of each xml attribute against an xml schema LeoMathew XSLT 0 December 7th, 2009 02:18 AM
Problem with date format in XML and XML Schema nelly78 XML 3 October 23rd, 2009 09:43 AM
create xml from xml schema in java zhebincong XML 1 October 6th, 2009 04:10 AM
Resolving entities when reading XML dmorin C# 0 September 25th, 2006 09:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.