0

i'm having trouble with my dtd file. i'm writing this for an order form. the order form has a case color, amount of batteries, recharger, arms, camera, and speech. what i am trying to do is incorporate the length of the arms. i have arms representing the amount of arms the customer choose, and the arm length is for the length of each arm. but i'm not sure how to write it in the dtd file. here is my dtd file so far.

<?xml version="1.0"?>
<!DOCTYPE orders [
<! ELEMENT orders (order)>
<! ELEMENT order (case, batteries, recharger, arm, camera, speech)>
<! ELEMENT case (#PCDATA)>
<! ELEMENT batteries (#PCDATA)>
<! ELEMENT recharger (#PCDATA)>
<! ELEMENT arm (#PCDATA)>
<! ELEMENT camera (#PCDATA)>
<! ELEMENT speech (#PCDATA)>
]>

this is how i would like to arm and length to be when the xml file is displayed

<arm> 2 
 <length> 50 </length>
 <length> 75 </length>
</arm>
Tim Post
  • 33,371
  • 15
  • 110
  • 174
beginnerprogrammer
  • 183
  • 2
  • 5
  • 22

1 Answers1

1

Are you trying to add the arm length to the arm element as an attribute? If so, this should work:

<!DOCTYPE orders [
<!ELEMENT orders (order)>
<!ELEMENT order (case, batteries, recharger, arm, camera, speech)>
<!ELEMENT case (#PCDATA)>
<!ELEMENT batteries (#PCDATA)>
<!ELEMENT recharger (#PCDATA)>
<!ELEMENT arm (#PCDATA)>
<!ATTLIST arm
          length CDATA #REQUIRED>
<!ELEMENT camera (#PCDATA)>
<!ELEMENT speech (#PCDATA)>
]>

If you don't want the length attribute to be required, change #REQUIRED to #IMPLIED.

Also, since your orders element only allows one order element orders isn't really needed. Maybe you want to allow more than one order? (<!ELEMENT orders (order+)>)

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95