Click to See Complete Forum and Search --> : 3 questions about schemas..


deanat78
11-20-2007, 06:44 PM
Hey guys
I have 3 unrelated questions about schemas, answering any of them would be appreciated:

1. Is there a way to tell the schema that the XML file must have the elements that the schema defines, but if there are other random elements in between, then just ignore them? Because I keep getting validation errors if I insert an element. Even when I don't use the 'sequence' element, but 'all' instead. Is there a way to allow that?

2. One of the elements contains data that is a list of words separated by commas with no spaces. The words are only certan specific words, so I wanted to use a list of enumerated strings. But it won't work because of the commas. Is there a way to tell the schema to use commas as a delimeter?

3. I have elements of name 'name' and each one of them has unique data. I have another element that has to match one of these names. I know that if I would give the name elements an 'id' attribute , I could use an 'idref' on the other element. But is there a way to achieve something similar, but instead of the attribute of the element, to do it with the text of the element?

Any information you give me will help.. thanks :)

jkmyoung
11-22-2007, 01:15 PM
1. you could use an xs:any in between the elements you expect random items.
2. No, not with xml schema.
3. See Key and Keyref
http://www.w3schools.com/schema/el_key.asp
http://www.w3schools.com/schema/el_keyref.asp

deanat78
11-22-2007, 11:28 PM
thanks, I'll look into that key stuff for number 3.

For 1. though, does xs:any have to go under <xs:sequence>? Because for me, the elements can be in any order, AND there might be more elements. So basically I just want to make sure that the elements that I define in the schema are present in the XML in some order.

I have
<xs:all>
<xs:element .../>
<xs:element .../>
<xs:any .../>
</xs:all>

But I can't do that because any is not allowed under all.. Do you have any suggestions..?
Thanks again

deanat78
11-23-2007, 11:11 AM
Thanks for your time padmkota. I'll leave that issue for now then, it seems that it's not very possible to do that

I do need a little more help though with regards to the <xs:key>/<xs:keyref> elements...
I looked it up but it seems that the key is an attribute? Maybe I'm not understanding it correctly, but it looks to me like the key is the value of an attribute, and that's not quite what I need to use..

I want something like this:
<people>
<sin>123</sin>
<sin>345</sin>
<sin>987</sin>
</people>
<king>345</king>

So every <sin> has to be different and that is my key, and the <king> element has to be one of those keys, so a keyref. How do I achieve this? Sorry if I'm just missing something very simple... :)

deanat78
11-23-2007, 02:01 PM
OK I solved it.. it did take me quite some time to get it to work...have a good weekend!