[
Lists Home |
Date Index |
Thread Index
]
- To: "'XML Developers List'" <xml-dev@lists.xml.org>
- Subject: forcing node content to match
- From: Doug Marttila <doug@visual-io.com>
- Date: Mon, 09 Jan 2006 15:14:21 -0500
- User-agent: Thunderbird 1.4 (Windows/20050908)
Hi,
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,
Node2=age, etc.)
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).
Thanks,
Doug
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
someone requests.
<forcingNodes_r xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="forceContent.xsd">
<var_o>
<nodeA>
<Node1>
<noValue_o hasValue_b="false"/>
</Node1>
<Node2>
<value_o hasValue_b="true" someMetric_n="10"/>
</Node2>
<Node3>
<noValue_o hasValue_b="false"/>
</Node3>
</nodeA>
<nodeB>
<Node1>
<noValue_o hasValue_b="false"/>
</Node1>
<Node2>
<value_o hasValue_b="true" value_n="20"/>
</Node2>
<Node3>
<noValue_o hasValue_b="false"/>
</Node3>
</nodeB>
</var_o>
</forcingNodes_r>
|