XML Schema Problem

  • Thread starter Thread starter Wee
  • Start date Start date

Wee

Wee

Associate
Joined
25 Apr 2006
Posts
130
Location
Scotland
I'm creating an XML document covering one of the groups in the Champoins League, and using a Schema to make sure it's valid and what not.

It's almost done, but I've hit a snag. I have a complex element, called goals, that contains another element, called scorer. It looks like this:

Code:
<goals>
   <scrorer number="1" time="62mins" team="Manchester United">Wayne Rooney</scrorer>
</goals>

My problem is that a game may finish 0 - 0, resulting in no goals, meaning that the scorer element won't be needed. Is there anyway in the Schema (or any other way) to take this into consideration?

Cheers.
 
<goals/>

I'm guessing you won't need any scorers, but the closed element will represent zero for you nicely

for your schema, you might want to use a single <scorer/> element rather than omitting it altogether, depending on how you're working it
 
This is my first go at XML, so bare with me as I'm not totally sure what you mean. :)

Does the <goal/> mean it will become an empty element? And if so, where does the scorer element fit into all of this?
 
yeah, I was just thinking that for your schema to validate, you'll probably have to use:

Code:
<goals>
  <scorer/>
</goals>

rather than just <goals/> - and yes, it becomes an empty element
 
Ah, got'cha. :)

So all the data for the element <scorer>, now that it is becoming an empty element, will need to be an attribute? Like so:

Code:
<goal>
<scorer number="1" time="62mins" player="Wayne Rooney" team="Manchester United"/>
</goal>
 
if it's a 0-0 game, there won't be any scorers though will there? an empty element (<scorer/>) and a full element (<scorer>Wayne Rooney</scorer>) are interchangeable in a valid schema. there's no need to add player attribute - only use the empty element if there's no scorers, otherwise, as you were doing in the OP
 
BUMP (mainy aimed at Sic):

EDIT FOR UPDATE:

I can now validate xs:string with the us of nillable="true" but this wont work for integer. google isnt helping much.

an empty element (<scorer/>) and a full element (<scorer>Wayne Rooney</scorer>) are interchangeable in a valid schema.

I am having very similar problems on validating empty elements (in my case empty elements with no attributes which i think is what causing the prob)


xml
Code:
 <REDCARDS>
    <NAME/>
    <TIME/>
 </REDCARDS>

So an complex element REDCARDS containing elements that may or may not be empty with no attributes.

how could i validate this in my Schema?

(what i have so far but not validating it)

xsd
Code:
 <xs:element name="REDCARDS" minOccurs="0" maxOccurs="unbounded">
            <xs:complexType>
                 <xs:sequence>
                     <xs:element name="NAME" type="xs:string" minOccurs="0" nillable="yes"/>
                     <xs:element name="TIME" type="xs:integer" minOccurs="0"/>
                  </xs:sequence>
            </xs:complexType>
</xs:element>
 
Last edited:
Back
Top Bottom