Automatically create XML schemas using XSLT

After this tutorial, I reworked the 733 line diagram in 16 separate files or subcircuits, each with its own namespace. Now the top-level scheme is only 77 lines. The plan is to use this subcircuit to create other top-level circuits.

The problem is that most top-level circuits are pretty similar and differ only in a few low-level details. For example, although one top-level scheme supports all PaymentMethodType (see the tutorial ), another top-level scheme can only support VISA and MasterCard. Currently, my method for creating top-level schemas involves significant duplication. For example, my current method of creating a top-level scheme that only supports VISA and MasterCard includes duplicating Main.xsd and OrderType.xsd , but setting CommonTypes.xsd and reusing CustomerTypes.xsd . (Since my actual layout is much longer, much more duplication is involved.)

I believe that this duplication is unacceptable in the first place because it introduces a maintenance problem, that is, I would have to support any number of identical subcircuits with different names.

What I would like to know is there a way to automatically create a circuit without using any configuration file (possibly XSLT?) To avoid duplicate subcircuits.

Also, is it good practice for all sub-schemes to declare the same task namespace in this case (same as the xml xs schema namespace, but user subcircuits declare a separate namespace?

+4
source share
2 answers

Why are you duplicating Main.xsd and OrderType.xsd instead of reusing them like you do CustomerTypes.xsd ? If they are literally identical (as the "duplicate" suggests), why not just import them? I suppose you can omit something from the question ...

In addition, it seems that the word "generating circuit without use" is missing.

  • A different namespace will work for each subcircuit; Another approach is "chameleon patterns." In this case, the subcircuits do not have a namespace, but use the namespace of the top-level scheme. Multi-Schema Project: Zero, One, or Many Namespaces? . However, this technique is a bit complicated, and not everyone supports it, so some suggest avoiding it . But for your case, maybe it's worth it ... Of course, reading these links will give you an idea of ​​how to deal with your situation.

  • You can redefine certain parts of another scheme (while the rest of this scheme will not change). Take a look at the defintion example below . It seems like this is the solution to your problem. Overridden parts can be low-level, which are used by other parts of the scheme (or other imported schemes). However, as with (1) above, this is a complex part of the specification that some tools may not support.

So ... I hope that your toolkit implements these features of the specification (and the toolkit of anyone else who should use them). You can test it with the example in the link above (I confirmed that it works with xmllint).

If not, your idea of ​​building subcircuits with XSLT (or another XML / text processing tool) will work. If you need special help with XSLT, I suggest that you include samples of the schema you are starting with and the resulting schema that you want.

0
source

I will not describe the XSLT-based approach, because I don’t know a single good thing because of the discovery that I see in my own hesitation: "something like (XSLT, maybe?)".

What you need, I tried this in 2004; Ive abandoned XSLT as the language to use when working with XML schema refactoring, because I am of the opinion that the schema object model APIs (SOM / XSOM), APIs designed specifically for analyzing and creating XSD, are much more productive of my time (for an XSLT reader reading this, Ive qualified my expression).

You always have the possibility that what you want is actually simple, therefore, you can use Roll-Your-Own-XSLT or otherwise (economically or intellectually). Exchanging more specific parameters for your problem can help give better answers. However, if you think about it professionally, that is, with minimal assumptions about what your input and output XSDs will look like, you are working for a little work.

What I ended up with was developing a Domain Specific Language for XML Schema refactoring. It is available as part of the QTAssistant XSR Module. Graphically, this is what your “733 line layout of 16 separate files or subcircuits” might look like in QTAssistant.

enter image description here

Its refactoring features allow a lot of what you described from one set of sources. All you need to do is configure the “views” you want with any necessary functions (for example, what happens in an XSD file, automatically pull out the necessary dependencies, change target namespaces, type refactory names, elements, replace basic type remove unwanted particles, introduce sequence wrappers to change power, etc.). A click of a button gives you guaranteed valid XSD files. It also features a command line interface for integration with automated build systems.

In any case, I would consider an API, for example, in .NET Schema , if only to breathe in how XSLT templates can be developed ...

-1
source

Source: https://habr.com/ru/post/1447563/


All Articles