DTD, #REQUIRED, #IMPLIED, Example

4.6k views Asked by At

I have a DTD-file,this is a part of it.It's written lv id ID #IMPLIED. As definition for #REQUIRED stays: "Elements can have zero or more attributes."That makes the code automatically correct,but could #IMPLIED be replaced with #REQUIRED,because the element here have already one attribute and no zero attributes,or I miss something?

<!ELEMENT lv (title, subtitle?, length, content, abstract)>
<!ATTLIST lv id ID #IMPLIED>

<!ELEMENT title (#PCDATA)>
<!ELEMENT subtitle (#PCDATA)>
<!ELEMENT abstract (#PCDATA)>

<!ELEMENT length EMPTY>
<!ATTLIST length value CDATA #REQUIRED
          unit (sws| h| min) "sws">

This is the associated XML-file:

<?xml version="1.0"?>
    <?xml-stylesheet href="lv.xsl" type="text/xsl"?>
    <!DOCTYPE lv SYSTEM "lehre.dtd">
    <lv id="wip2">
      <title>WI-Praktikum 2</title>
      <subtitle>Verarbeitung strukturierter Daten</subtitle>
      <length value="2" unit="sws"/>
      <content>
        <topic>Grundlagen</topic>
        <topic>Grammatiken</topic>
        <topic>SAX</topic>
      </content>
      <abstract>
      Der Kurs vermittelt den Aufbau und die Verarbeitung von XML-Dokumenten.
      Als Programmiersprachen kommen Java, Python und XSLT zum Einsatz.
      </abstract>
    </lv>
1

There are 1 answers

1
Daniel Haley On BEST ANSWER

I'm not sure I completely understand your question, but yes you can change #IMPLIED to #REQUIRED in the attribute declaration for the attribute id on the element li.

The attribute id is the type ID so it has to have a default of either #IMPLIED or #REQUIRED. Which one is up to you.

You must also have only one ID type attribute declared for an element, but your DTD already satisfies that requirement so nothing to worry about there.

See the spec (3.3 Attribute-List Declarations) for more info.