XML

Solutions XML.1

Assignment XML.1.0

Download and study http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd , the XHTML DTD.

Answer the following questions:

  1. Must input elements be inside forms?
  2. Find and name the EMPTY elements.
  3. May a table be empty? May a tr?
  4. What are the possible attributes of a h2?
Solution XML.1.0
1. Must input elements be inside forms?
nmlinux tmp $ grep '<!ELEMENT form' *.dtd
<!ELEMENT form %form.content;>   <!-- forms shouldn't be nested -->

nmlinux tmp $ grep 'form.content' *.dtd
<!ENTITY % form.content "(%block; | %misc;)*">

nmlinux tmp $ grep '% misc' *.dtd
<!ENTITY % misc.inline "ins | del | script">

nmlinux tmp $ grep '% block' *.dtd
<!ENTITY % blocktext "pre | hr | blockquote | address">                // no good, this was blocktext

nmlinux tmp $ grep -HnC 3 '%blocktext' *.dtd
xhtml1-strict.dtd-200-<!ENTITY % blocktext "pre | hr | blockquote | address">
xhtml1-strict.dtd-201-
xhtml1-strict.dtd-202-<!ENTITY % block
xhtml1-strict.dtd:203:     "p | %heading; | div | %lists; | %blocktext; | fieldset | table">
xhtml1-strict.dtd-204-
xhtml1-strict.dtd-205-<!ENTITY % Block "(%block; | form | %misc;)*">   // interesting block on level with form
        </listitem>
2. Find and name the EMPTY elements.
nmlinux tmp $ grep EMPTY *.dtd
<!ELEMENT base EMPTY>
<!ELEMENT meta EMPTY>
<!ELEMENT link EMPTY>
<!ELEMENT hr EMPTY>
<!ELEMENT br EMPTY>   <!-- forced line break -->
<!ELEMENT param EMPTY>
<!ELEMENT img EMPTY>
<!ELEMENT area EMPTY>
<!ELEMENT input EMPTY>     <!-- form control -->
<!ELEMENT col      EMPTY>
nmlinux tmp $
3. May a table be empty? May a tr?

nmlinux tmp $ grep -HnC 3 'table' *.dtd
...
xhtml1-strict.dtd:854:<!ELEMENT table
xhtml1-strict.dtd-855-     (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>
4. What are the possible attributes of a h2?

nmlinux tmp $ grep -Hn h2 *.dtd
xhtml1-strict.dtd:198:<!ENTITY % heading "h1|h2|h3|h4|h5|h6">

xhtml1-strict.dtd:378:<!ELEMENT h2 %Inline;>
xhtml1-strict.dtd:379:<!ATTLIST h2
xhtml1-strict.dtd-380-   %attrs;
xhtml1-strict.dtd-381-   >

nmlinux tmp $ grep -HnC 5 '% attrs' *.dtd
xhtml1-strict.dtd:167:<!ENTITY % attrs "%coreattrs; %i18n; %events;">
xhtml1-strict.dtd-168-
xhtml1-strict.dtd-169-<!--=================== Text Elements ====================================-->
xhtml1-strict.dtd-170-
xhtml1-strict.dtd-171-<!ENTITY % special.pre
xhtml1-strict.dtd-172-   "br | span | bdo | map">

nmlinux tmp $ grep -HnC 5 '% coreattrs' *.dtd
xhtml1-strict.dtd-107-  id       document-wide unique id
xhtml1-strict.dtd-108-  class    space separated list of classes
xhtml1-strict.dtd-109-  style    associated style info
xhtml1-strict.dtd-110-  title    advisory title/amplification
xhtml1-strict.dtd-111--->
xhtml1-strict.dtd:112:<!ENTITY % coreattrs
xhtml1-strict.dtd-113- "id          ID             #IMPLIED
xhtml1-strict.dtd-114-  class       CDATA          #IMPLIED
xhtml1-strict.dtd-115-  style       %StyleSheet;   #IMPLIED
xhtml1-strict.dtd-116-  title       %Text;         #IMPLIED"
xhtml1-strict.dtd-117-  >

nmlinux tmp $ grep -HnC 5 '% i18n' *.dtd
xhtml1-strict.dtd-119-<!-- internationalization attributes
xhtml1-strict.dtd-120-  lang        language code (backwards compatible)
xhtml1-strict.dtd-121-  xml:lang    language code (as per XML 1.0 spec)
xhtml1-strict.dtd-122-  dir         direction for weak/neutral text
xhtml1-strict.dtd-123--->
xhtml1-strict.dtd:124:<!ENTITY % i18n
xhtml1-strict.dtd-125- "lang        %LanguageCode; #IMPLIED
xhtml1-strict.dtd-126-  xml:lang    %LanguageCode; #IMPLIED
xhtml1-strict.dtd-127-  dir         (ltr|rtl)      #IMPLIED"
xhtml1-strict.dtd-128-  >
xhtml1-strict.dtd-129-

nmlinux tmp $ grep -HnC 5 '% events' *.dtd
xhtml1-strict.dtd-136-  onmouseout  a pointer was moved away from the element
xhtml1-strict.dtd-137-  onkeypress  a key was pressed and released
xhtml1-strict.dtd-138-  onkeydown   a key was pressed down
xhtml1-strict.dtd-139-  onkeyup     a key was released
xhtml1-strict.dtd-140--->
xhtml1-strict.dtd:141:<!ENTITY % events
xhtml1-strict.dtd-142- "onclick     %Script;       #IMPLIED
xhtml1-strict.dtd-143-  ondblclick  %Script;       #IMPLIED
xhtml1-strict.dtd-144-  onmousedown %Script;       #IMPLIED
xhtml1-strict.dtd-145-  onmouseup   %Script;       #IMPLIED
xhtml1-strict.dtd-146-  onmouseover %Script;       #IMPLIED
Example B.105. testInput.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Must be here</title>
    <style type="text/css">
        table {
            border: 1px solid red;
        }
        tr {
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <h1>test input</h1>
    <p><input type="text" value="test"/></p>
    <table></table>
    <table><tr></tr></table>
</body>
</html>

Live from your's truly's localhost.


Assignment XML.1.1

Study the following xml-document

Example B.106. booksCanon.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE booksCanon SYSTEM "booksCanon.dtd">
<booksCanon>
  <book ref="Llo08" mycanon="mdu,all">
    <title>Learn How to Build Web Sites the Right Way from Scratch</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Ian</firstname>
        <lastname>Lloyd</lastname>
      </author>
    </authors>
    <publisher>
      <name>SitePoint</name>
      <year>2008</year>
      <place>Collingwood, VIC, Australia</place>
    </publisher>
    <pages>300</pages>
    <isbn></isbn>
    <price>9.73</price>
    <currency>EU&#8364;</currency>
    <comments>
      <comment>1. sem: Chapters 1-7</comment>
    </comments>
  </book>
  
  <book ref="Shu08" mycanon="mdu">
    <title>Learning ActionScript 3.0</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Rich</firstname>
        <lastname>Shupe</lastname>
      </author>
      <author>
        <firstname>Zevan</firstname>
        <lastname>Rosser</lastname>
      </author>
    </authors>
    <publisher>
      <name>O'Reilly</name>
      <year>2008</year>
      <place>Sebastopol, CA, USA</place>
    </publisher>
    <pages>384</pages>
    <isbn>978-0596527877</isbn>
    <price>8.73</price>
    <currency>US$</currency>
    <comments>
      <comment>1. sem: Chapters 1-7</comment>
    </comments>
  </book>
  
  <book ref="Nix09" mycanon="mdu">
    <title>Learning PHP, MySQL, and JavaScript</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Robin</firstname>
        <lastname>Nixon</lastname>
      </author>
    </authors>
    <publisher>
      <name>O'Reilly</name>
      <year>2009</year>
      <place>Sebastopol, CA, USA</place>
    </publisher>
    <pages>120</pages>
    <isbn></isbn>
    <price></price>
    <currency></currency>
    <comments>
      <comment>2. sem: Chapters 1-7, 11, 14-17</comment>
      <comment>3. sem: Chapters 8-10</comment>
    </comments>
  </book>

  <book ref="For04" mycanon="mdu,all">
    <title>SQL in 10 Minutes</title>
    <edition>3</edition>
    <authors>
      <author>
        <firstname>Ben</firstname>
        <lastname>Forta</lastname>
      </author>
    </authors>
    <publisher>
      <name>Sams Publishing</name>
      <year>2004</year>
      <place>Indianapolis, IN, USA</place>
    </publisher>
    <pages></pages>
    <isbn></isbn>
    <price>120</price>
    <currency></currency>
    <comments>
      <comment>3. sem: Chapters 1-17</comment>
    </comments>
  </book>
  
</booksCanon>

Create a DTD for the booksCanon.xml, Name it booksCanon.dtd. Validate booksCanon.xml against the dtd.

Solution XML.1.1
Example B.107. booksCanon.dtd
<?xml version='1.0' encoding='UTF-8'?>

<!--
    TODO define vocabulary identification
    PUBLIC ID: -//vendor//vocabulary//EN
    SYSTEM ID: http://server/path/booksCanon.dtd

-->

<!--
    An example how to use this DTD from your XML document:

    <?xml version="1.0"?>

    <!DOCTYPE booksCanon SYSTEM "booksCanon.dtd">

    <booksCanon>
    ...
    </booksCanon>
-->

<!--- Put your DTDDoc comment here. -->
<!ELEMENT booksCanon (book)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT book (comments|currency|price|isbn|pages|publisher|authors|edition|title)*>
<!ATTLIST book
    mycanon CDATA #IMPLIED
    ref CDATA #IMPLIED
  >

<!--- Put your DTDDoc comment here. -->
<!ELEMENT title (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT edition (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT authors (author)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT author (lastname|firstname)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT firstname (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT lastname (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT publisher (place|year|name)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT name (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT year (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT place (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT pages (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT isbn (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT price (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT currency (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT comments (comment)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT comment (#PCDATA)>

Example B.108. booksXML1.dtd
<?xml version='1.0' encoding='UTF-8'?>

<!--
    TODO define vocabulary identification
    PUBLIC ID: -//vendor//vocabulary//EN
    SYSTEM ID: http://server/path/booksXML1.dtd

-->

<!--
    An example how to use this DTD from your XML document:

    <?xml version="1.0"?>
    <!DOCTYPE booklist SYSTEM "booksXML1.dtd">
    <booklist>
    ...
    </booklist>
-->

<!--- Put your DTDDoc comment here. -->
<!ELEMENT booklist (book)*>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT book (quantity|price|currency|publisher|author|title)*>
<!ATTLIST book
    type CDATA #IMPLIED
  >

<!--- Put your DTDDoc comment here. -->
<!ELEMENT title (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT author (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT publisher (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT currency (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT price (#PCDATA)>

<!--- Put your DTDDoc comment here. -->
<!ELEMENT quantity (#PCDATA)>

Assignment XML.1.2

Create an XML Schema for the booksCanon.xml, Name it booksCanon.xsd. Validate booksCanon.xml against the schema.

Solution XML.1.2
Example B.109. booksCanon.xsd
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE schema [
<!ENTITY euro "&#8364;">
]>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
        <xs:appinfo>
            Just testing
        </xs:appinfo>   
        <xs:documentation>
            Documentation for canonical books
        </xs:documentation>   
    </xs:annotation>
    
    <xs:complexType name="myBookList">
        <xs:sequence>
            <xs:element name="book" type="myBooks" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="myBooks">
        <xs:sequence>
            <xs:element name="title" type="xs:string" />
            <xs:element name="edition" type="xs:positiveInteger" minOccurs="0" />
            <xs:element name="authors" type="authorDef" />
            <xs:element name="publisher" type="publishers" />
            <xs:element name="pages" type="xs:positiveInteger" minOccurs="0" />
            <xs:element name="isbn" type="xs:string" />
            <xs:element name="price" type="xs:decimal" />
            <xs:element name="currency" type="currencies" />
            <xs:element name="comments" type="commentsDef" />
            <!-- a number of elements to form the sequence -->
        </xs:sequence>
        <xs:attribute name="ref" type="xs:string" />
        <xs:attribute name="mycanon" type="xs:string" />
        <!-- a number of attributes -->
    </xs:complexType>
    
    <xs:complexType name="authorDef">
        <xs:sequence>
            <xs:element name="author" type="authorDet" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="authorDet">
        <xs:sequence>
            <xs:element name="firstname" type="xs:string" />
            <xs:element name="lastname" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="publishers">
        <xs:sequence>
            <xs:element name="name" type="xs:string" />
            <xs:element name="year" type="xs:positiveInteger" />
            <xs:element name="place" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="commentsDef">
        <xs:sequence>
            <xs:element name="comment" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
    
    <xs:simpleType name="currencies">
        <xs:restriction base="xs:string">
            <xs:enumeration value="GBP" />
            <xs:enumeration value="DKR" />
            <xs:enumeration value="US$" />
            <xs:enumeration value="EU&euro;" />
        </xs:restriction>
    </xs:simpleType>
    
    <xs:element name="booksCanon" type="myBookList" />
</xs:schema>

Example B.110. booksXML2.xml
<?xml version="1.0" encoding="UTF-8"?>
<booksCanon
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="booksCanon.xsd">

  <book ref="Llo08" mycanon="mdu,all">
    <title>Learn How to Build Web Sites the Right Way from Scratch</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Ian</firstname>
        <lastname>Lloyd</lastname>
      </author>
    </authors>
    <publisher>
      <name>SitePoint</name>
      <year>2008</year>
      <place>Collingwood, VIC, Australia</place>
    </publisher>
    <pages>300</pages>
    <isbn></isbn>
    <price>9.73</price>
    <currency>EU&#8364;</currency>
    <comments>
      <comment>1. sem: Chapters 1-7</comment>
    </comments>
  </book>
  
  <book ref="Shu08" mycanon="mdu">
    <title>Learning ActionScript 3.0</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Rich</firstname>
        <lastname>Shupe</lastname>
      </author>
      <author>
        <firstname>Zevan</firstname>
        <lastname>Rosser</lastname>
      </author>
    </authors>
    <publisher>
      <name>O'Reilly</name>
      <year>2008</year>
      <place>Sebastopol, CA, USA</place>
    </publisher>
    <pages></pages>
    <isbn>978-0596527877</isbn>
    <price>8.73</price>
    <currency>US$</currency>
    <comments>
      <comment>1. sem: Chapters 1-7</comment>
    </comments>
  </book>
  
  <book ref="Nix09" mycanon="mdu">
    <title>Learning PHP, MySQL, and JavaScript</title>
    <edition>2</edition>
    <authors>
      <author>
        <firstname>Robin</firstname>
        <lastname>Nixon</lastname>
      </author>
    </authors>
    <publisher>
      <name>O'Reilly</name>
      <year>2009</year>
      <place>Sebastopol, CA, USA</place>
    </publisher>
    <pages>120</pages>
    <isbn>123</isbn>
    <price>12.98</price>
    <currency>EU&#8364;</currency>
    <comments>
      <comment>2. sem: Chapters 1-7, 11, 14-17</comment>
      <comment>3. sem: Chapters 8-10</comment>
    </comments>
  </book>

  <book ref="For04" mycanon="mdu,all">
    <title>SQL in 10 Minutes</title>
    <edition>3</edition>
    <authors>
      <author>
        <firstname>Ben</firstname>
        <lastname>Forta</lastname>
      </author>
    </authors>
    <publisher>
      <name>Sams Publishing</name>
      <year>2004</year>
      <place>Indianapolis, IN, USA</place>
    </publisher>
    <pages>100</pages>
    <isbn></isbn>
    <price>120</price>
    <currency>DKR</currency>
    <comments>
      <comment>3. sem: Chapters 1-17</comment>
    </comments>
  </book>
  
</booksCanon>