[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Possible to use wildcards in schema element names?
- From: Hermann Stamm-Wilbrandt <STAMMW@de.ibm.com>
- To: Kevin Gibbs <kevin.kgibbs@gmail.com>
- Date: Sat, 27 Nov 2010 01:44:36 +0100
Hi Jimmy,
> My question then is, "Is it possible, in the schema, to use wildcards
> or regex for the field elements?
No, the name attribute of xsd:element is of type NCName:
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-element
And a NCName is a XML Name without a colon:
http://www.w3.org/TR/REC-xml-names/#NT-NCName
But if you know a maximal number of different field elements (eg. 9):
(maxOccurs default value is "1")
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element ref="name"/>
<xs:element ref="field1" minOccurs="0"/>
<xs:element ref="field2" minOccurs="0"/>
<xs:element ref="field3" minOccurs="0"/>
<xs:element ref="field4" minOccurs="0"/>
<xs:element ref="field5" minOccurs="0"/>
<xs:element ref="field6" minOccurs="0"/>
<xs:element ref="field7" minOccurs="0"/>
<xs:element ref="field8" minOccurs="0"/>
<xs:element ref="field9" minOccurs="0"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:NCName"/>
<xs:element name="field1" type="xs:NCName"/>
<xs:element name="field2" type="xs:NCName"/>
<xs:element name="field3" type="xs:NCName"/>
<xs:element name="field4" type="xs:NCName"/>
<xs:element name="field5" type="xs:NCName"/>
<xs:element name="field6" type="xs:NCName"/>
<xs:element name="field7" type="xs:NCName"/>
<xs:element name="field8" type="xs:NCName"/>
<xs:element name="field9" type="xs:NCName"/>
</xs:schema>
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
Fixpack team lead
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
From: Kevin Gibbs <kevin.kgibbs@gmail.com>
To: xml-dev <xml-dev@lists.xml.org>
Date: 11/26/2010 11:12 PM
Subject: [xml-dev] Possible to use wildcards in schema element names?
Hi all,
I'm trying to generate a schema for some xml (for which I have no
control over the format)
Consider the following xml example:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<name>Bill</name>
<field1>abc</field1> <!-- any number of fields -->
<field2>def</field2>
<field3>ghi</field3>
<field4>jkl</field4>
<name>John</name>
<field3>uvw</field3> <!-- need not start with field1 -->
<field4>xyz</field4>
</document>
As you can see, each "name" element has a varying number of "field*"
siblings.
So, I've come with the following attempt (the eagle-eyed among you,
may notice that I'm no expert):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element ref="name"/>
<xs:element ref="field" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="name" type="xs:NCName"/>
<xs:element name="field*" type="xs:NCName"/> <!-- How is it possible
to
perform wildcard? -->
</xs:schema>
My question then is, "Is it possible, in the schema, to use wildcards
or regex for the field elements?
Many thanks in anticipation - Jimmy
_______________________________________________________________________
XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.
[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]