Lists Home |
Date Index |
- To: "'XML Developers List'" <email@example.com>
- Subject: forcing node content to match
- From: Doug Marttila <firstname.lastname@example.org>
- Date: Mon, 09 Jan 2006 15:14:21 -0500
- User-agent: Thunderbird 1.4 (Windows/20050908)
I am writing an xsd and want the content of one node to force the
content of another. The explanation for why I need this is rather long
(if anyone's interested, I'd be happy to share).
The best way to describe the problem is as an example...
A parentNode has two child nodes, NodeA and NodeB.
NodeA can have 3 nodes - Node1, Node2, etc. These nodes are different
and could even be attributes. (If NodeA defined a person, Node1=name,
NodeB must match the structure of NodeA. So, if NodeA has a value for
Node1, NodeB must have a value for Node1. And, if NodeA does not have a
value, NodeB cannot.
What I've ended up doing is adding child nodes to Node1, 2, etc. - so
that Node1, instead of having a value, actually has a choice - that
choice is a value node and a noValue node. Then using key/keyRefs and
restricted attributes (restricted to 1 value - true or false) I can
force NodeB to match up.
Hopefully that makes sense. The solution works - but, results in verbose
xml (nodes describe themselves as having no value instead of just not
existing) and seems pretty klugey. Is there a better way to do this w/
an xsd? Or - is there another technology that can be used to achieve
this? I am only familiar with xsds and xml. Other technologies are
discussed on this list that I know nothing about (e.g., schematron).
below is some sample xml that might better describe the problem. I also
have a sample xsd - but, it's rather long (125 lines). I'll post if
<value_o hasValue_b="true" someMetric_n="10"/>
<value_o hasValue_b="true" value_n="20"/>