Given the following xml-snippet:
<Environment>
...
<MySqlConfiguration>
<ActiveServer>1@db1</ActiveServer>
<PassiveServer>2@db1</PassiveServer>
<Replicate from="1@db1" to="2@db1" />
<Replicate from="2@db1" to="1@db1" />
</MySqlConfiguration>
...
</Environment>
I want to restrict from/to values to those specified in ActiveServer or PassiveServer
in XSD, I try the following:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath=".//ActiveServer|PassiveServer"/>
<xs:field xpath="*"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
However, the xpath="*" field selector in the key does not work (it does not get the text node of the Active/PassiveServer elements). xpath="text()" does not work either. Doing something like:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath="Environment"/>
<xs:field xpath="ActiveServer|PassiveServer"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
Does not work (field must refer to one instance; specifying just one of those would work).
Is there some way I’m overlooking on how to grab an element’s text content in a field xpath value?
I would expect the following to work:
Note “|” has lowest precedence so the “.//” needs to be repeated. The BNF from XSD Rec: