Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had a similar question: <a href="https://stackoverflow.com/questions/1348753/xml-schema-key-with-multiple-fields">XML Schema Key with multiple fields</a></p> <p>I decided that the best approach for me was to reorder the XML to allow for the scope to be determined by locality instead of enforcing a key with two fields.</p> <p>In your scenario, if you move referrer inside the parent, this will allow the scope to be set to reference the appropriate child. You would then have the referrer element refer to the outer scope to the element that it needs to reference.</p> <p>It is a little hard to determine if this is an acceptable solution because your problem appears to be a little abstracted. In my problem, described in my question, I was dealing with questions, answers, and user responses. I originally was trying to validate if a user's response was actually a valid answer; my first approach involved a same technique you are using. My final solution involved moving the response to inside the question, and then referring to the user.</p> <p>My XML BEFORE:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;survey&gt; &lt;user id="bob"&gt; &lt;response questionIdRef="q101"&gt;yes&lt;/response&gt; &lt;response questionIdRef="q102"&gt;white&lt;/response&gt; &lt;/user&gt; &lt;user id="jane"&gt; &lt;response questionIdRef="q101"&gt;no&lt;/response&gt; &lt;response questionIdRef="q102"&gt;blue&lt;/response&gt; &lt;/user&gt; &lt;question id="q101"&gt; &lt;text&gt;Do you like the color red?&lt;/text&gt; &lt;answer&gt;yes&lt;/answer&gt; &lt;answer&gt;no&lt;/answer&gt; &lt;/question&gt; &lt;question id="q102"&gt; &lt;text&gt;What is your favorite color?&lt;/text&gt; &lt;answer&gt;red&lt;/answer&gt; &lt;answer&gt;blue&lt;/answer&gt; &lt;answer&gt;white&lt;/answer&gt; &lt;answer&gt;yellow&lt;/answer&gt; &lt;/question&gt; &lt;/survey&gt; </code></pre> <p>My XML AFTER:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;survey&gt; &lt;user id="bob" /&gt; &lt;user id="jane" /&gt; &lt;question id="q101"&gt; &lt;text&gt;Do you like the color red?&lt;/text&gt; &lt;answer&gt;yes&lt;/answer&gt; &lt;answer&gt;no&lt;/answer&gt; &lt;response userIdRef="bob"&gt;yes&lt;/response&gt; &lt;response userIdRef="jane"&gt;no&lt;/response&gt; &lt;/question&gt; &lt;question id="q102"&gt; &lt;text&gt;What is your favorite color?&lt;/text&gt; &lt;answer&gt;red&lt;/answer&gt; &lt;answer&gt;blue&lt;/answer&gt; &lt;answer&gt;white&lt;/answer&gt; &lt;answer&gt;yellow&lt;/answer&gt; &lt;response userIdRef="bob"&gt;white&lt;/response&gt; &lt;response userIdRef="jane"&gt;blue&lt;/response&gt; &lt;/question&gt; &lt;/survey&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload