You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Joanne Bogart <jr...@slac.stanford.edu> on 2005/06/02 22:25:17 UTC

IDREFS equivalent for XML schema?

Hi,

I apologize in advance for this question, which is most likely about XML 
Schema and not about Xerces; however maybe somebody out there has 
already encountered this issue.

I'm writing my first moderately complicated XML Schema; I have much more 
experience with dtd's. If I were writing a dtd for this application, it 
would include something like

<!ELEMENT anElt ...>
<!ATTLIST anElt name ID #REQUIRED ..  >

<!ELEMENT anotherElt ...>
<!ATTLIST  anotherElt refs IDREFS #REQUIRED .. >

however, here I prefer to use XML Schema key and keyref because of the 
ability to limit scope. I've tried something like this, where xs is the 
prefix for XML schema namespace:

<xs:element name="anElt" ...>

     <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
...
</xs:element>


<xs:element name="anotherElt" ..>
     <xs:attribute name="refs" type="xs:NMTOKENS: use="required" />
  ..
</xs:element>


and then

<xs:key name="anEltKey">
    <xs:selector xpath="anElt" />
    <xs:field     xpath="@name" />
</xs:key>

<xs:keyref name="anotherRef" refer="anEltKey" >
    <xs:selector xpath="anotherElt" />
    <xs:field     xpath="@refs" />
</xs:keyref>

This works as long as the value of the anotherRef attribute in the 
instance document is just a single token. If it's more than one, Xerces 
complains with an identity constraint error. Is there some way (in the 
2nd xs:field element above) to express the idea of selecting each token 
within the attribute string?   I haven't found anything like this in the 
XPATH spec. Or is there some other concise way to get the effect of 
ID/IDREFS plus the nice scoping?

Thanks,
Joanne


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: IDREFS equivalent for XML schema?

Posted by Joanne Bogart <jr...@slac.stanford.edu>.
Hi Neil,
Thanks for the quick and definitive response. At least now I know not to 
keep looking for something that isn't there.

best regards,
Joanne

Neil Graham wrote:

>Hi Joanne,
>
>One of the constraints on key/keyref is that the value of the keyref must 
>be equal to the value of the key referred to. A single value can't be 
>equal, in XML Schema terms, with a list of values.  So no, I don't believe 
>there's any way to do what you want with identity constraints. 
>
>Note that schema does define id, idref and idrefs, so you can certainly do 
>with them what you used to do with DTD's.
>
>Cheers,
>Neil
>Neil Graham
>Manager, XML Parser Development
>IBM Toronto Lab
>Phone:  905-413-3519, T/L 969-3519
>E-mail:  neilg@ca.ibm.com
>
>
>
>
>
>Joanne Bogart <jr...@slac.stanford.edu> 
>06/02/2005 04:25 PM
>Please respond to
>c-dev
>
>
>To
>c-dev@xerces.apache.org
>cc
>
>Subject
>IDREFS equivalent for XML schema?
>
>
>
>
>
>
>Hi,
>
>I apologize in advance for this question, which is most likely about XML 
>Schema and not about Xerces; however maybe somebody out there has 
>already encountered this issue.
>
>I'm writing my first moderately complicated XML Schema; I have much more 
>experience with dtd's. If I were writing a dtd for this application, it 
>would include something like
>
><!ELEMENT anElt ...>
><!ATTLIST anElt name ID #REQUIRED ..  >
>
><!ELEMENT anotherElt ...>
><!ATTLIST  anotherElt refs IDREFS #REQUIRED .. >
>
>however, here I prefer to use XML Schema key and keyref because of the 
>ability to limit scope. I've tried something like this, where xs is the 
>prefix for XML schema namespace:
>
><xs:element name="anElt" ...>
>
>     <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
>...
></xs:element>
>
>
><xs:element name="anotherElt" ..>
>     <xs:attribute name="refs" type="xs:NMTOKENS: use="required" />
>  ..
></xs:element>
>
>
>and then
>
><xs:key name="anEltKey">
>    <xs:selector xpath="anElt" />
>    <xs:field     xpath="@name" />
></xs:key>
>
><xs:keyref name="anotherRef" refer="anEltKey" >
>    <xs:selector xpath="anotherElt" />
>    <xs:field     xpath="@refs" />
></xs:keyref>
>
>This works as long as the value of the anotherRef attribute in the 
>instance document is just a single token. If it's more than one, Xerces 
>complains with an identity constraint error. Is there some way (in the 
>2nd xs:field element above) to express the idea of selecting each token 
>within the attribute string?   I haven't found anything like this in the 
>XPATH spec. Or is there some other concise way to get the effect of 
>ID/IDREFS plus the nice scoping?
>
>Thanks,
>Joanne
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: IDREFS equivalent for XML schema?

Posted by Neil Graham <ne...@ca.ibm.com>.
Hi Joanne,

One of the constraints on key/keyref is that the value of the keyref must 
be equal to the value of the key referred to. A single value can't be 
equal, in XML Schema terms, with a list of values.  So no, I don't believe 
there's any way to do what you want with identity constraints. 

Note that schema does define id, idref and idrefs, so you can certainly do 
with them what you used to do with DTD's.

Cheers,
Neil
Neil Graham
Manager, XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  neilg@ca.ibm.com





Joanne Bogart <jr...@slac.stanford.edu> 
06/02/2005 04:25 PM
Please respond to
c-dev


To
c-dev@xerces.apache.org
cc

Subject
IDREFS equivalent for XML schema?






Hi,

I apologize in advance for this question, which is most likely about XML 
Schema and not about Xerces; however maybe somebody out there has 
already encountered this issue.

I'm writing my first moderately complicated XML Schema; I have much more 
experience with dtd's. If I were writing a dtd for this application, it 
would include something like

<!ELEMENT anElt ...>
<!ATTLIST anElt name ID #REQUIRED ..  >

<!ELEMENT anotherElt ...>
<!ATTLIST  anotherElt refs IDREFS #REQUIRED .. >

however, here I prefer to use XML Schema key and keyref because of the 
ability to limit scope. I've tried something like this, where xs is the 
prefix for XML schema namespace:

<xs:element name="anElt" ...>

     <xs:attribute name="name" type="xs:NMTOKEN" use="required" />
...
</xs:element>


<xs:element name="anotherElt" ..>
     <xs:attribute name="refs" type="xs:NMTOKENS: use="required" />
  ..
</xs:element>


and then

<xs:key name="anEltKey">
    <xs:selector xpath="anElt" />
    <xs:field     xpath="@name" />
</xs:key>

<xs:keyref name="anotherRef" refer="anEltKey" >
    <xs:selector xpath="anotherElt" />
    <xs:field     xpath="@refs" />
</xs:keyref>

This works as long as the value of the anotherRef attribute in the 
instance document is just a single token. If it's more than one, Xerces 
complains with an identity constraint error. Is there some way (in the 
2nd xs:field element above) to express the idea of selecting each token 
within the attribute string?   I haven't found anything like this in the 
XPATH spec. Or is there some other concise way to get the effect of 
ID/IDREFS plus the nice scoping?

Thanks,
Joanne


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org