[web] xml - how to organise this

Started by
1 comment, last by evolutional 19 years, 4 months ago
ok, this is a doublepost from the "for beginners" .. I was suggested to try here ... this is what puzzels me for now. I am going to create an xml document with a dtd. and this is what I have to record.

Olympic Atlanta 1996
  Results sprint 100m
     person: Donovan Bailey (Canada)    time: 09.84
     person: Michael March (USA)    time: 10.00
  results sprint 200m
     ....

Next olympic...
What I see here is that I can create one record of persons (name, country ++ ), and one record (game, type, results ). But wether I make an xml doc based on (game, type) and record athletes and their results .... or based on (name, country ++ ) and record game, type, results.

<?xml version="1.0"?>
<!DOCTYPE doc_root [
	<!ELEMENT doc_root (event*)>
	<!ELEMENT event (name, place, year, athletes*)>
	<!ELEMENT name (#PCDATA)>
	<!ELEMENT place (#PCDATA)>
	<!ELEMENT year (#PCDATA)>
	
	<!ELEMENT athletes (firstname, lastname, country, results*)>
	<!ELEMENT firstname (#PCDATA)>
	<!ELEMENT lastname (#PCDATA)>
	<!ELEMENT country (#PCDATA)>
	
	<!ELEMENT results (category*)>
	
	<!ELEMENT category (cat_name, type*)>
	<!ELEMENT cat_name (#PCDATA)>
	
	<!ELEMENT type (typ_name, result)>
	<!ELEMENT typ_name (#PCDATA)>
	<!ELEMENT result (#PCDATA)>
]>
<doc_root>
	<event>
		<name>Olympic games</name>
		<place>Atlanta</place>
		<year>1996</year>
		<athletes>
			<firstname>Michael</firstname>
			<lastname>March</lastname>
			<country>USA</country>
			<results>
				<category>
					<cat_name>Sprint</cat_name>
					<type>
						<typ_name>100m</typ_name>
						<result>10.00</result>
					</type>
					<type>
						<typ_name>200m</typ_name>
						<result>20.48</result>
					</type>
				</category>
			</results>
		</athletes>
		<athletes>
			<firstname>Michael</firstname>
			<lastname>Johnson</lastname>
			<country>USA</country>
			<results>
				<category>
					<cat_name>Sprint</cat_name>
					<type>
						<typ_name>200m</typ_name>
						<result>19.32</result>
					</type>
				</category>
			</results>
		</athletes>
	</event>
	<event>
		<name>Olympic games</name>
		<place>Barcelona</place>
		<year>1992</year>
		<athletes>
			<firstname>Donovan</firstname>
			<lastname>Bailey</lastname>
			<country>Canada</country>
			<results>
				<category>
					<cat_name>Sprint</cat_name>
					<type>
						<typ_name>100m</typ_name>
						<result>09.84</result>
					</type>
				</category>
			</results>
		</athletes>
	</event>
</doc_root>




or...

<?xml version="1.0"?>
<!DOCTYPE doc_root [
	<!ELEMENT doc_root (event*)>
	<!ELEMENT event (name, place, year, results*)>
	<!ELEMENT name (#PCDATA)>
	<!ELEMENT place (#PCDATA)>
	<!ELEMENT year (#PCDATA)>
	<!ELEMENT results (category*)>
	<!ELEMENT category (cat_name, type*)>
	<!ELEMENT cat_name (#PCDATA)>
	<!ELEMENT type (typ_name, athletes*)>
	<!ELEMENT typ_name (#PCDATA)>
	<!ELEMENT athletes (firstname, lastname, result, country)>
	<!ELEMENT firstname (#PCDATA)>
	<!ELEMENT lastname (#PCDATA)>
	<!ELEMENT result (#PCDATA)>
	<!ELEMENT country (#PCDATA)>
]>
<doc_root>
	<event>
		<name>Olympiske leker</name>
		<place>Atlanta</place>
		<year>1996</year>
		<results>
			<category>
				<cat_name>Sprint</cat_name>
				<type>
					<typ_name>100m</typ_name>
					<athletes>
						<firstname>Michael</firstname>
						<lastname>March</lastname>						
						<result>09.84</result>
						<country>USA</country>
					</athletes>
					<athletes>
						<firstname>Donovan</firstname>
						<lastname>Bailey</lastname>						
						<result>10.00</result>
						<country>Canada</country>
					</athletes>
				</type>
				<type>
					<typ_name>200m</typ_name>
					<athletes>
						<firstname>Michael</firstname>
						<lastname>March</lastname>						
						<result>19.32</result>
						<country>USA</country>
					</athletes>
					<athletes>
						<firstname>Michael</firstname>
						<lastname>Bailey</lastname>						
						<result>20.48</result>
						<country>Canada</country>
					</athletes>
				</type>
			</category>
		</results>
	</event>
	<event>
		<name>Olympiske leker</name>
		<place>Barcelona</place>
		<year>1992</year>
		<results>
			<category>
				<cat_name>Sprint</cat_name>
				<type>
					<typ_name>100m</typ_name>
				</type>
				<type>
					<typ_name>200m</typ_name>
				</type>
			</category>
		</results>
	</event>
</doc_root>




if there is a better way to avoid re-typing the same info over and over again, tell me about it. Now I have to choose to retype each athletes, or each game ...
Advertisement
If u want to avoid retyping athletes, u can give each athlete an attribute named id with the attribute's type as ID. When u refer the that athlete, use an element named like athleteref with an attribute id of type IDREF. Note that the ID and IDREF types in DTD can only be used on attributes, not elements (XSD allows both).

For more informations on ID and IDREF types, use google :-)

Same goes for games.
I'd be more inclined to construct my XML document like this:

<Data>	<Games name="Olympic" location="Atlanta" year="1996">		<Event type="sprint">			<Type value="100m>				<Athlete name="Donovan Bailey" origin="Canada" time="09.84" />				<Athlete name="Michael March" origin="USA" time="10.00" />			</Type>		</Event>	</Games></Data>


What you're experiencing is one of the drawbacks of a badly structured XML document, it can become hugely bloated. However, I'm not sure exactly what you're using this data for and as such, my method might not be the one you're after. So, in order to understand your data requirement, you'll need to understand the problem domain. Who's using the data? How will it be read? Who will supply it?

This topic is closed to new replies.

Advertisement