Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 Q's: schema that allows more elements, comma-separated list., 1 more 2

Status
Not open for further replies.

deanat78

Programmer
Feb 9, 2007
7
CA
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 :)
 
[1-Q:1] Use <xs:any> element.
[2-Q:2] Use xs:restriction with xs:pattern where you set the pattern corresponding to the acceptable comma-delimited text.
[3-Q:3] Use <xs:key> to establish the key, and use <xs:keyref> to script the contraint on the structure of the other nodes where the constraint is to be applied.
 
Thanks a lot, I'll take a look at your suggestions for 2 and 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
 
And now about the <xs:key> and <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...
 
OK I solved it.. it did take me quite some time to solve it though... enjoy your weekends :)
 
[1.1]
>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..

One of the most severe constraint on the construction of the content model in WXSL is the unique particle attribution. One consequence of it is the rejection of <xs:any> in the <xs:all> compositor, because invariably the particle attribution is ambiguous. It is not an independent rule. Under many circomstances, even in the xs:sequence or xs:choice compositors, the ambiguity would easily arise and hence being rejected by the same rule.

[1.2] >Do you have any suggestions..?
In this circumstances, within WXSL, the better way is to wrap the wild part of the tags in an element of a definitive name - that is crucial ingredient to eliminate the ambiguity and hence to observe the unique attribution rule.

[1.2.1] The xs:all elements, like this.
[tt]
<!-- global declaration -->
<!-- a,b,c xs:string or more complicated construction -->
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
<xs:element name="c" type="xs:string" />
<xs:element name="x">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="##any" processContents="skip" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:group name="stable">
<xs:all>
<xs:element ref="a" minOccurs="0" />
<xs:element ref="b" minOccurs="0" />
<xs:element ref="c" minOccurs="0" />
<xs:element ref="x" minOccurs="0" />
</xs:all>
</xs:group>
[/tt]
[1.2.2] The parent node, let's say named p, is constructed like this.
[tt]
<xs:element name="p">
<xs:complexType>
<xs:group ref="stable" />
</xs:complexType>
</xs:element>
[/tt]
[1.2.3] The result will be that these instances are valid.
[tt]
<p>
<a>string-a</a>
<b>string-b</b>
<c>string-c</c>
</p>
<p>
<c>string-c</c>
<a>string-a</a>
<b>string-b</b>
</p>
<p>
<c>string-c</c>
<b>string-b</b>
</p>
<p>
<c>string-c</c>
<a>string-a</a>
<b>string-b</b>
<x>string-any</x>
</p>
<p>
<b>string-b</b>
<x>string-any</x>
<a>string-a</a>
</p>
<p>
<x>string-any</x>
<a>string-a</a>
<c>string-c</c>
<b>string-b</b>
<!-- <a>string-a</a> --> <!-- will be invalidated -->
</p>
<p>
<x>
<y>string-y</y>
</x>
<a>string-a</a>
<c>string-c</c>
<b>string-b</b>
</p>
<!-- etc etc -->
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top