Kind of tamplating XML schema

A

Albretch Mueller

Hi,

I have an XML schema which maxOccurs and minOccurs may changed based on
some external settings.( This is why I set it via
maxOccurs="$test.maxOccurs")

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="$test.maxOccurs" minOccurs="0" name="tpk">
<xs:complexType>
<xs:attribute name="Ix" type="xs:nonNegativeInteger" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

which I keep in properties files and after reading them I could easily
changed via an api call like:

http://java.sun.com/j2se/1.5.0//docs/api/java/lang/System.html#setProperty(j
ava.lang.String,%20java.lang.String)

However XML is not letting me do that.

How could you do something like?

Thanks
 
J

John C. Bollinger

Albretch said:
I have an XML schema which maxOccurs and minOccurs may changed based on
some external settings.( This is why I set it via
maxOccurs="$test.maxOccurs")

Then no, you do not have *a* schema. You have a family of related
schemata, or at best a collection of different versions of one schema.

If the number of required combinations of minoccurs and maxoccurs is
reasonably small, then you might be better served by doing this the
"right" way in schema-ese, which would probably be to use an abstract
outer type having specific concrete types distinguished by name and
occurrence constraints in its content model. Otherwise, you might be
better served by employing application-level logic to test the
occurrence constraints.
<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="$test.maxOccurs" minOccurs="0" name="tpk">
<xs:complexType>
<xs:attribute name="Ix" type="xs:nonNegativeInteger" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

which I keep in properties files and after reading them I could easily
changed via an api call like:

http://java.sun.com/j2se/1.5.0//docs/api/java/lang/System.html#setProperty(j
ava.lang.String,%20java.lang.String)

However XML is not letting me do that.

I'm not sure what you mean by that. You mean the built-in parsers do
not provide a mechanism to honor parameterized schemata? Naturally they
don't: it's a foreign concept to XML and XML Schema. See also below.
How could you do something like?

Why do you want to? XML Schema is not primarily designed for validating
random XML documents; rather, it is designed to provide a _shared_
contract between a document creator and a document consumer regarding
the structure of XML documents. As such, it makes no sense to configure
a schema instance at runtime. It seems that either your schema is too
simple or you are trying to place responsibilities on it that more
rightfully belong to the application.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top