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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to XML, need some DTD help...

Status
Not open for further replies.

twopecker

Technical User
Oct 25, 2006
3
US
I have the following file:

<?xml version="1.0" ?>
<!DOCTYPE League SYSTEM "DL.dtd">
<League LName="Eastern Developmental League">
<Team>
<Team_Name>Tigers</Team_Name>
<City>Toledo</City>
<Logo Source="Tigers"/>
<Players>
<Player Position="Centers" PPG="21.2" RPG="11.1">Lionel Diggs</Player>
<Player Position="Forward" PPG="18.9" RPG="8.4">Andrew Case</Player>
<Player Position="Forward" PPG="14.4" RPG="5.0">Casey Lewis</Player>
<Player Position="Guard" PPG="15.4" RPG="3.1" Assists="9.4">Andrew Case</Player>
<Player Position="Guard" PPG="7.2" RPG="2.5" Assists="3.9">Ray Kee</Player>
</Players>
</Team>
<Team>

And I am trying to make the following DTD file, but im not sure how to handle the "player" portion:

<!DOCTYPE League[

<!ELEMENT League (Team+)>
<!ELEMENT Team (#PCDATA)>

<!ELEMENT Team (Team_Name, City, Logo, Players+)>
<!ELEMENT Team_Name (#PCDATA)>
<!ELEMENT City (#PCDATA)>
<!ELEMENT Logo EMPTY>
<!ELEMENT Players (Player, Position, PPG, RPG)
<!ELEMENT Player>
<!ELEMENT Position ANY>
<!ELEMENT PPG ANY>
<!ELEMENT RPG ANY>


<!ATTLIST League Team CDATA #REQUIRED>
<!ATTLIST Team Logo CDATA #REQUIRED>
<!ATTLIST Player Position (Center|Forward|Guard)>


]>


Can anyone help a new guy out a bit? I've been going through all the tutorials I can find, but am sitll having problems.

Thanks!
Marcus
 
Marcus,

I am no DTD expert, but here is what Stylus Studio generated.
Code:
<!ELEMENT League (Team)+>
<!ATTLIST League
  xmlns CDATA #FIXED ''
  LName CDATA #REQUIRED>

<!ELEMENT Team (Team_Name,City,Logo,Players)>
<!ATTLIST Team
  xmlns CDATA #FIXED ''>

<!ELEMENT Team_Name (#PCDATA)>
<!ATTLIST Team_Name
  xmlns CDATA #FIXED ''>

<!ELEMENT City (#PCDATA)>
<!ATTLIST City
  xmlns CDATA #FIXED ''>

<!ELEMENT Logo EMPTY>
<!ATTLIST Logo
  xmlns CDATA #FIXED ''
  Source  #REQUIRED>

<!ELEMENT Players (Player)+>
<!ATTLIST Players
  xmlns CDATA #FIXED ''>

<!ELEMENT Player (#PCDATA)>
<!ATTLIST Player
  xmlns CDATA #FIXED ''
  Assists  #IMPLIED
  PPG  #REQUIRED
  Position  #REQUIRED
  RPG  #REQUIRED>

Don't know if this is helpful or not.

Tom Morrison
 
Thanks for the reply...and im not sure if its helpful or not either. =)

I just bought a book to try to learn xml..sadly, i realized just a little ways in that it seems to be a text book with no answers! argh!

What do the entries for xmlns mean?
 
Centers"
PPG="21.2"
RPG="11.1"
Assists="9.4"
etc.

are not elements, they are just attributes of the Player element, hence they should be included just in the <!ATTLIST> declarations i guess.
I'd say it might look something like this:

Code:
<!ELEMENT players (player)>
<!ELEMENT Player (#PCDATA)>
<!ATTLIST Player Position (Center|Forward|Guard) #REQUIRED>

<!ATTLIST Player PPG CDATA #IMPLIED "21.2">
etc.
note: use #IMPLIED or #FIXED instead of #REQUIRED if needed

The same ought to go for the
<!ELEMENT Players (Player, Position, PPG, RPG)



"Position, PPG, RPG" are not elements, just attributes of the "Player" element hence cannot be stated as child elements of the "Players" element => Players(Position, PPG,RPG);

it is in deed only the "Player" that is the child element of the "Players" element, the others u had stated are just "Player"'s attributes.

And be careful about the tag ending signs.

<!ELEMENT Players (Player, Position, PPG, RPG)

I am just a rookie as well, so I could be wrong.
Cheers
 
Actually, with what you provided, and then with venedos help, I was able to get it to work.

Quite the painful first experience though!

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top