diff --git a/Doc/Sda1/dom.xml b/Doc/Sda1/dom.xml index ac416c9bb8ecfabf938a7e2ce9bf6d01109be3f6..967f45118883fd36b037e98c11ee97c698b59a23 100644 --- a/Doc/Sda1/dom.xml +++ b/Doc/Sda1/dom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<chapter version="5.1" xml:id="dom" xmlns="http://docbook.org/ns/docbook" +<chapter annotations="slide" version="5.1" xml:id="dom" + xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes" xmlns:xi="http://www.w3.org/2001/XInclude" @@ -176,7 +177,7 @@ public interface Node { an example:</para> <figure xml:id="domRetrieveChildren"> - <title>Retrieving child nodes of a given context node</title> + <title>A context node's children</title> <mediaobject> <imageobject> @@ -185,23 +186,37 @@ public interface Node { </mediaobject> </figure> - <para>The <classname>org.w3c.dom.Node</classname> interface offers a set - of common operations for objects being part of a XML document. But a XML - document tree contains different types of nodes such as:</para> + <figure xml:id="sda1_dom_nodeTypes"> + <title><classname>org.w3c.dom.Node</classname> subtypes</title> - <itemizedlist> - <listitem> - <para>Elements</para> - </listitem> + <itemizedlist> + <listitem> + <para>Element</para> + </listitem> - <listitem> - <para>Attributes</para> - </listitem> + <listitem> + <para>Text</para> + </listitem> - <listitem> - <para>Entities</para> - </listitem> - </itemizedlist> + <listitem> + <para>Comment</para> + </listitem> + + <listitem> + <para>Processing instruction</para> + + <programlisting language="xml"><?xml-stylesheet type="text/xsl" href="style.xsl"?></programlisting> + </listitem> + + <listitem> + <para>Entity</para> + </listitem> + + <listitem> + <para>...</para> + </listitem> + </itemizedlist> + </figure> <para>An XML API may address this issue by offering data types to represent these different kinds of nodes. The <acronym @@ -210,9 +225,8 @@ public interface Node { interfaces for this purpose:</para> <figure xml:id="domJavaNodeInterfaces"> - <title>Inheritance interface hierarchy in the <acronym - xlink:href="https://www.w3.org/DOM">DOM</acronym> <xref - linkend="glo_Java"/> binding</title> + <title><acronym xlink:href="https://www.w3.org/DOM">DOM</acronym> <xref + linkend="glo_Java"/> binding inheritance interface hierarchy</title> <mediaobject> <imageobject> @@ -240,62 +254,73 @@ public interface Node { </imageobject> </mediaobject> </figure> - </section> - <section xml:id="domCreate"> - <title>Creating a new document from scratch</title> + <figure xml:id="sda1_fig_usingJdom"> + <title>Using <xref linkend="glo_Jdom"/></title> - <titleabbrev>New document</titleabbrev> - - <para>This lecture's exercises are based on <xref linkend="glo_Jdom"/> in - favour of a <quote>real</quote> Java <xref linkend="glo_DOM"/> language - binding implementation.</para> + <glosslist> + <glossentry> + <glossterm>Advantage:</glossterm> - <glosslist> - <glossentry> - <glossterm>Advantage:</glossterm> - - <glossdef> - <itemizedlist> - <listitem> - <para>More Java compatible i.E. using native collection - interfaces</para> - </listitem> - - <listitem> - <para>Less clumsy avoiding the need for class factory based - parser instantiation.</para> - </listitem> - </itemizedlist> - </glossdef> - </glossentry> - - <glossentry> - <glossterm>Disadvantages:</glossterm> - - <glossdef> - <para><itemizedlist> + <glossdef> + <itemizedlist> <listitem> - <para>Set apart from the standard.</para> + <para>Alternative to <orgname + xlink:href="https://docs.oracle.com/javase/8/docs/api/org/w3c/dom/package-frame.html">org.w3c.dom</orgname>.</para> </listitem> <listitem> - <para>May lack advanced features.</para> + <para>More Java compatible <abbrev>i.e.</abbrev> using <link + xlink:href="https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html">native + collection interfaces</link></para> </listitem> <listitem> - <para>Less mature on account of a smaller user - community.</para> + <para>Less clumsy avoiding the need for class factory based + parser instantiation.</para> </listitem> + </itemizedlist> + </glossdef> + </glossentry> - <listitem> - <para>Potentially incompatible when using other frameworks - providing <xref linkend="glo_DOM"/> related interfaces.</para> - </listitem> - </itemizedlist></para> - </glossdef> - </glossentry> - </glosslist> + <glossentry> + <glossterm>Disadvantages:</glossterm> + + <glossdef> + <para><itemizedlist> + <listitem> + <para>Set apart from the standard.</para> + </listitem> + + <listitem> + <para>May lack advanced features.</para> + </listitem> + + <listitem> + <para>Less mature on account of a smaller user + community.</para> + </listitem> + + <listitem> + <para>Potentially incompatible when using other frameworks + providing <xref linkend="glo_DOM"/> related + interfaces.</para> + </listitem> + </itemizedlist></para> + </glossdef> + </glossentry> + </glosslist> + </figure> + </section> + + <section xml:id="domCreate"> + <title>Creating a new document from scratch</title> + + <titleabbrev>New document</titleabbrev> + + <para>This lecture's exercises are based on <xref linkend="glo_Jdom"/> in + favour of a <quote>real</quote> Java <xref linkend="glo_DOM"/> language + binding implementation.</para> <para>Using <xref linkend="glo_Jdom"/> requires your project to configure libraries from <uri xlink:href="http://jdom.org">http://jdom.org</uri>. @@ -303,25 +328,36 @@ public interface Node { effected by adding the following section to your <filename>pom.xml</filename>:</para> - <programlisting language="xml"> <dependencies> - .... - <emphasis role="bold"><!-- Jdom itself --></emphasis> - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - <version>2.0.6</version> - </dependency> - - <emphasis role="bold"><!-- XPath support for Jdom --></emphasis> - <dependency> - <groupId>jaxen</groupId> - <artifactId>jaxen</artifactId> - <version>1.1.4</version> - </dependency> - ...</programlisting> - - <para>If we want to export non-XML content (e.g. from a RDBMS) into XML we - may achieve this by the following recipe:</para> + <figure xml:id="sda1_fig_jdomMavenConfig"> + <title>Maven <filename>pom.xml</filename> configuration.</title> + + <programlisting language="xml"><dependency> <emphasis role="bold"><!-- Jdom itself --></emphasis> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> +</dependency> + + +<dependency> <emphasis role="bold"><!-- XPath support for Jdom --></emphasis> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.4</version> +</dependency> ...</programlisting> + </figure> + + <para>If we want wrap data (<abbrev>e.g.</abbrev> from a + <acronym>RDBMS</acronym>) into XML we may achieve this by the following + recipe:</para> + + <figure xml:id="sda1_fig_exportXml"> + <title>Exporting data as XML</title> + + <mediaobject> + <imageobject> + <imagedata fileref="???"/> + </imageobject> + </mediaobject> + </figure> <orderedlist> <listitem> @@ -352,11 +388,8 @@ public interface Node { <figure xml:id="simpleDomCreate"> <title>Creation of a XML document instance from scratch.</title> - <programlisting language="java">package dom; -... -public class CreateDoc { + <programlisting language="java">public class CreateDoc { public static void main(String[] args) throws Exception { - // Create the root element <emphasis role="bold">final Element titel = new Element("titel"); </emphasis> @@ -373,14 +406,15 @@ public class CreateDoc { // Serialize to console <emphasis role="bold">final XMLOutputter printer = new XMLOutputter(outFormat); printer.output(titel, System.out);</emphasis> - } -}</programlisting> + }}</programlisting> </figure> - <para>We get the following result:</para> + <para><figure xml:id="sda1_dom_createResult"> + <title>Serializing result</title> - <programlisting language="xml"><?xml version="1.0" encoding="UTF-8"?> -<titel date="23.02.2000">Versuch 1</titel></programlisting> + <screen language="xml"><?xml version="1.0" encoding="UTF-8"?> +<titel date="23.02.2000">Versuch 1</titel></screen> + </figure></para> </section> <section xml:id="domCreateExercises">