[
Lists Home |
Date Index |
Thread Index
]
I have trouble understanding how to use namespaces with XML Schema, without
loosing the control of the overall xml document structure. In order to
understand the problem better I have formulated a few simple "problems"
which I hope somebody would help me find possible solutions for.
I understand that in a schema, I cannot define elements from more than one
namespace, but I can include elements from other namespaces. (I also know
that I can create new elements of a type which is defined in another
namespace. However, this does not solve my base problem, I think, since I
want to make the different namespaces visible in the XML document through
use of prefixes.)
My problem originated in a work with RDF/XML, which seems to require its own
namespace prefix and the exact local name corresponding to the RDF term. I
tried to use RDF/XML with traditional documents (encoding the document
metadata as RDF/XML), but I find this a more general problem than that. For
example, when working with file transfer between application inside a
company, or between companies, I would like to have control over the
structure of the exchange file through one single XML Schema, or through a
number of "interlinked" (?) XML Schemas, if necessary.
PROBLEM 1
Can I validate an XML document containing elements from different namespaces
against either
a) one XML Schema
b) several XML schema
What would the schema a.xsd look like in the example below? I would like to
have the different namespaces visible through different prefixes, as in the
example, and I would like to preserve the local names given in the original
namespace. If it helps, I could accept using a namespace (preferably
default) for all elements in the schema a.xsd.
I am also interested in solutions to example documents which are very
similar to mine, but don't alter the internal relationship between the
presented elements, e.g. containing more "container elements" or such.
Example document:
<?xml version="1.0">
<a1 xsi:noNamespaceSchemaLocation="a.xsd"
xmlns:b="http:\\example.org\b\"
xmlns:c="http:\\example.org\c\">
<b:b1>This is element B1 from namespace B</b:b1>
<a2>This is the second element from schema a</a2>
<c:c1>This element is from namespace c</c:c1>
</a1>
PROBLEM 2
Can I nest the namespaces in such an XML document, so that elements from one
namespace contains elements from other namespaces, and still validate my XML
document against one or several XML Schemas?
Example document:
<?xml version="1.0">
<a1 xsi:noNamespaceSchemaLocation="a.xsd"
xmlns:b="http:\\example.org\b\"
xmlns:c="http:\\example.org\c\">
<b:b2>
<b:b1>This is element B1 from namespace B</b:b1>
<c:c1>This element is from namespace c</c:c1>
</b:b2>
</a1>
PROBLEM 3
Can elements from one namespace occur several times in a hierarchy where
elements from other namespaces occur as fathers, i.e. true nesting, and
still validate my XML document against one or several XML Schemas? And how
would the XML Schemas that defines those namespaces look like?
Example document:
<?xml version="1.0">
<a1 xsi:noNamespaceSchemaLocation="a.xsd"
xmlns:b="http:\\example.org\b\"
xmlns:c="http:\\example.org\c\">
<b:b2>
<b:b1>This is element B1 from namespace B.</b:b1>
<a2>This is the second element from schema a</a2>
<c:c2>
<c:c1>This element is from namespace c</c:c1>
<b:b1>This is element B1 from namespace B.</b:b1>
</c:c2>
</b:b2>
</a1>
PROBLEM 4
Can I, using the example from my problem 3, enforce (through validation)
that instances are created with exactly those elements, occuring just one
time each, with one single XML Schema?
If not, what degree of enforcement can I achieve with one single XML schema?
and with several?
Thanks a lot, anyone, for helping me find references or solutions for the
above!
Peter
--
Peter Bergstrom
Eurostep AB
Vasagatan 38
SE-111 20 Stockholm
Sweden
mobile phone: +46 708 111 966
mobile fax: +46 708 111 965
home office fax: +46 470 711 930
http://www.eurostep.com/
Open solutions for open organisations and people
|