diff --git a/Doc/Sda1/dom.xml b/Doc/Sda1/dom.xml index e6722c63be1a6f535b2215144589818e3de0b9b1..8e17b0d6fd09afe7b39549831d88df1d177abc43 100644 --- a/Doc/Sda1/dom.xml +++ b/Doc/Sda1/dom.xml @@ -196,7 +196,7 @@ xlink:href="http://www.omg.org/gettingstarted/corbafaq.htm">CORBA 2.2</productname> <abbrev>IDL</abbrev></title> - <programlisting language="c++">interface Node { + <programlisting language="C++">interface Node { const unsigned short ELEMENT_NODE = 1; // NodeType const unsigned short ATTRIBUTE_NODE = 2; const unsigned short TEXT_NODE = 3; @@ -441,12 +441,13 @@ public interface Node { // Node Types <callout arearefs="sda1_dom_createXmlFromScratch-4-co" xml:id="sda1_dom_createXmlFromScratch-4"> <para>Create a serializer instance of <classname - xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/output/XMLOutputter.html">XMLOutputter</classname>.</para> + xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/output/XMLOutputter.html">XMLOutputter</classname> + providing output prettifying.</para> </callout> <callout arearefs="sda1_dom_createXmlFromScratch-5-co" xml:id="sda1_dom_createXmlFromScratch-5"> - <para>Serialize the resulting tree to a stream.</para> + <para>Serialize the result tree to a stream.</para> </callout> </calloutlist> </figure> @@ -536,10 +537,14 @@ printer.output(titel, System.out); <co document. The <link linkend="simpleCatalog">simple catalog</link> serves as an introductory example:</para> - <programlisting language="xml"><catalog> + <figure xml:id="sda1_dom_catalogSampleData"> + <title><xref linkend="glo_XML"/> catalog sample data</title> + + <programlisting language="xml"><catalog> <item orderNo="3218">Swinging headset</item> <item orderNo="9921">200W Stereo Amplifier</item> </catalog></programlisting> + </figure> <para>We already noticed the need for an <classname xlink:href="http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html">ErrorHandler</classname> @@ -555,42 +560,92 @@ printer.output(titel, System.out); <co xlink:href="https://docs.oracle.com/javase/9/docs/api/org/xml/sax/ErrorHandler.html">ErrorHandler</classname> interface we may use for the sake of conveying parsing errors:</para> - <programlisting language="java">public class MySaxErrorHandler implements ErrorHandler { + <figure xml:id="sda1_dom_saxErrorHandler"> + <title><xref linkend="glo_SAX"/> error handler</title> - private PrintStream out; //The error handler's output goes here + <programlisting language="java">public class <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/P/Sda1/Jdom/Catalog/src/main/java/sax/MySaxErrorHandler.java">MySaxErrorHandler</link> implements <link + xlink:href="https://docs.oracle.com/javase/9/docs/api/org/xml/sax/ErrorHandler.html">ErrorHandler</link> { - private String getParseExceptionInfo //Returns a string describing - (SAXParseException ex) { //parse exception details. - return "Error '" + ex.getMessage() + "' at line " + - ex.getLineNumber() + ", column " + - ex.getColumnNumber(); - } + private PrintStream out; <co linkends="sda1_dom_saxErrorHandler-1" + xml:id="sda1_dom_saxErrorHandler-1-co"/>//The error handler's output goes here - /** - * @param out Report's destination - */ - public MySaxErrorHandler(final PrintStream out) { - this.out = out; + private String getParseExceptionInfo <co + linkends="sda1_dom_saxErrorHandler-2" + xml:id="sda1_dom_saxErrorHandler-2-co"/>(SAXParseException ex) { + return "Error '" + ex.getMessage() + "' at line " + ex.getLineNumber() + + ", column " + ex.getColumnNumber(); } - @Override - public void warning(SAXParseException exception) throws SAXException { + public MySaxErrorHandler(final PrintStream out <co + linkends="sda1_dom_saxErrorHandler-3" + xml:id="sda1_dom_saxErrorHandler-3-co"/>) {this.out = out;} + @Override public void warning<co linkends="sda1_dom_saxErrorHandler-4" + xml:id="sda1_dom_saxErrorHandler-4-co"/> (SAXParseException exception <co + linkends="sda1_dom_saxErrorHandler-5" + xml:id="sda1_dom_saxErrorHandler-5-co"/>) throws SAXException { out.print("Warning:" + getParseExceptionInfo(exception)); } - @Override - public void error(SAXParseException exception) throws SAXException { + @Override public void error <co linkends="sda1_dom_saxErrorHandler-6" + xml:id="sda1_dom_saxErrorHandler-6-co"/>(SAXParseException exception <coref + linkend="sda1_dom_saxErrorHandler-3-co"/>) throws SAXException { out.print("Error:" + getParseExceptionInfo(exception)); - } - @Override - public void fatalError(SAXParseException exception) throws SAXException { + } @Override + public void fatalError <co linkends="sda1_dom_saxErrorHandler-7" + xml:id="sda1_dom_saxErrorHandler-7-co"/>(SAXParseException exception <coref + linkend="sda1_dom_saxErrorHandler-3-co"/>) throws SAXException { out.print("Fatal error:" + getParseExceptionInfo(exception)); } }</programlisting> + </figure> + + <calloutlist> + <callout arearefs="sda1_dom_saxErrorHandler-1-co" + xml:id="sda1_dom_saxErrorHandler-1"> + <para>Error and warning messages go here. The underlying stream may be + linked <abbrev>e.g.</abbrev> to a file or to standard output.</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-2-co" + xml:id="sda1_dom_saxErrorHandler-2"> + <para>Internal method assembling the actual error or warning message + containing a line number / column number based file reference.</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-3-co" + xml:id="sda1_dom_saxErrorHandler-3"> + <para>Constructor for defining the respective stream.</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-4-co" + xml:id="sda1_dom_saxErrorHandler-4"> + <para>Callback method being called in case of minor problems i.e. a + missing mandatory attribute.</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-5-co" + xml:id="sda1_dom_saxErrorHandler-5"> + <para>The exception instance holding a detailed problem + description</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-6-co" + xml:id="sda1_dom_saxErrorHandler-6"> + <para>Severe error.</para> + </callout> + + <callout arearefs="sda1_dom_saxErrorHandler-7-co" + xml:id="sda1_dom_saxErrorHandler-7"> + <para>Fatal error <abbrev>e.g.</abbrev> indicating improper nesting of + elements prohibiting further parsing of the given <xref + linkend="glo_XML"/> input.</para> + </callout> + </calloutlist> <para>We use this bit to assemble a <xref linkend="glo_DOM"/> based <xref linkend="glo_XML"/> parsing application:.</para> <figure xml:id="sda1_dom_fig_TreeTraversal"> - <title>Accessing a XML Tree purely by <xref linkend="glo_DOM"/> + <title>Accessing an XML Tree purely by <xref linkend="glo_DOM"/> methods.</title> <programlisting language="java">public class <link @@ -638,21 +693,21 @@ printer.output(titel, System.out); <co xml:id="sda1_dom_fig_TreeTraversal-2.2"> <para>Though an <classname xlink:href="https://docs.oracle.com/javase/9/docs/api/org/xml/sax/ErrorHandler.html">ErrorHandler</classname> - is not strictly being required it allows for easier localization of - XML document errors</para> + is not strictly being required it allows for localization of XML + document parsing errors and warnings.</para> </callout> <callout arearefs="sda1_dom_fig_TreeTraversal-3.2-co" xml:id="sda1_dom_fig_TreeTraversal-3.2"> <para>Descending a catalog till its <tag class="starttag">item</tag> - elements. For each product its name and order number are being written - to the output.</para> + elements. For each <tag class="starttag">item</tag> its name and order + number are being written to the output.</para> </callout> <callout arearefs="sda1_dom_fig_TreeTraversal-4.2-co" xml:id="sda1_dom_fig_TreeTraversal-4.2"> - <para>Parsing error being thrown in case of non-wellformed catalog - documents.</para> + <para>Parsing error being thrown in <abbrev>i.e.</abbrev> case of non- + wellformed catalog documents.</para> </callout> <callout arearefs="sda1_dom_fig_TreeTraversal-5.2-co" @@ -673,11 +728,14 @@ printer.output(titel, System.out); <co </callout> </calloutlist> - <para>Executing this method needs a driver instance providing an <xref - linkend="glo_XML"/> input filename:</para> + <para>Execution of <methodname>process(...)</methodname> requires a driver + instance providing an <xref linkend="glo_XML"/> input filename:</para> - <programlisting language="java">public class <link - xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/P/Sda1/Jdom/Catalog/src/main/java/dom/ReadCatalogDriver.java">ReadCatalogDriver</link> { + <figure xml:id="sda1_dom_fig_readCatalogDriver"> + <title>Driver class execution entry point</title> + + <programlisting language="java">public class <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/P/Sda1/Jdom/Catalog/src/main/java/dom/ReadCatalogDriver.java">ReadCatalogDriver</link> { public static void main(String[] argv) throws Exception { final ReadCatalog catalogReader = new ReadCatalog(); @@ -685,16 +743,16 @@ printer.output(titel, System.out); <co } }</programlisting> - <para>This yields:</para> - - <screen>Article: Swinging headset, order number: 3218 + <screen>Article: Swinging headset, order number: 3218 Article: 200W Stereo Amplifier, order number: 9921</screen> + </figure> - <para>This example's complete code may is available for import:</para> + <figure xml:id="sda1_dom_fig_readCatalogSampleProject"> + <title>Project sample code for import</title> - <annotation role="make"> - <para role="eclipse">Sda1/Jdom/Catalog</para> - </annotation> + <para><uri + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/P/Sda1/Jdom/Catalog">https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/tree/master/P/Sda1/Jdom/Catalog</uri></para> + </figure> </section> <section xml:id="sda1SimpleDomProcess"> @@ -1514,24 +1572,20 @@ public class Article2Html { class="starttag">img</tag> tags.</title> <programlisting language="xml"><html xmlns="http://www.w3.org/1999/xhtml"> - <head> - <title>Picture gallery</title> - </head> + <head><title>Picture gallery</title></head> <body> <h1>Picture gallery</h1> <p>Images may appear inline:<emphasis role="red"><img src="inline.gif" alt="none"/></emphasis></p> - <table> - <tbody> - <tr> - <td>Number one:</td> - <td><emphasis role="red"><img src="one.gif" alt="none"/></emphasis></td> - </tr> - <tr> - <td>Number two:</td> - <td><emphasis role="red"><img src="http://www.hdm-stuttgart.de/favicon.ico" alt="none"/></emphasis></td> - </tr> - </tbody> - </table> + <table><tbody> + <tr> + <td>Number one:</td> + <td><emphasis role="red"><img src="one.gif" alt="none"/></emphasis></td> + </tr> + <tr> + <td>Number two:</td> + <td><emphasis role="red"><img src="http://www.hdm-stuttgart.de/favicon.ico" alt="none"/></emphasis></td> + </tr> + </tbody></table> </body> </html></programlisting> </figure> @@ -1649,46 +1703,45 @@ static final XPathExpression<Element> xpathSearchImg = xml:id="sda1_dom_fig_domXpathImgSearch-4-co"/>, htmlNamespace <co linkends="sda1_dom_fig_domXpathImgSearch-5" xml:id="sda1_dom_fig_domXpathImgSearch-5-co"/>);</programlisting> + </figure> - <calloutlist> - <callout arearefs="sda1_dom_fig_domXpathImgSearch-1-co" - xml:id="sda1_dom_fig_domXpathImgSearch-1"> - <para>Associating prefix <code>html</code> and <xref - linkend="glo_HTML"/> namespace - <code>http://www.w3.org/1999/xhtml</code>.</para> - </callout> + <calloutlist> + <callout arearefs="sda1_dom_fig_domXpathImgSearch-1-co" + xml:id="sda1_dom_fig_domXpathImgSearch-1"> + <para>Associating prefix <code>html</code> and <xref + linkend="glo_HTML"/> namespace + <code>http://www.w3.org/1999/xhtml</code>.</para> + </callout> - <callout arearefs="sda1_dom_fig_domXpathImgSearch-2-co" - xml:id="sda1_dom_fig_domXpathImgSearch-2"> - <para>Searching <tag class="starttag">img</tag> elements belonging - to the namespace <code>http://www.w3.org/1999/xhtml</code> linked by - the <code>html</code> prefix.</para> - </callout> + <callout arearefs="sda1_dom_fig_domXpathImgSearch-2-co" + xml:id="sda1_dom_fig_domXpathImgSearch-2"> + <para>Searching <tag class="starttag">img</tag> elements belonging to + the namespace <code>http://www.w3.org/1999/xhtml</code> linked by the + <code>html</code> prefix.</para> + </callout> - <callout arearefs="sda1_dom_fig_domXpathImgSearch-3-co" - xml:id="sda1_dom_fig_domXpathImgSearch-3"> - <para>Selecting only <classname - xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/Element.html">Element</classname> - instances rather than other sub classed objects below <link - xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/Content.html">Content</link>.</para> - </callout> + <callout arearefs="sda1_dom_fig_domXpathImgSearch-3-co" + xml:id="sda1_dom_fig_domXpathImgSearch-3"> + <para>Selecting only <classname + xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/Element.html">Element</classname> + instances rather than other sub classed objects below <link + xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/Content.html">Content</link>.</para> + </callout> - <callout arearefs="sda1_dom_fig_domXpathImgSearch-4-co" - xml:id="sda1_dom_fig_domXpathImgSearch-4"> - <para>Using no parameters. See <link - xlink:href="http://www.jdom.org/pipermail/jdom-interest/2012-May/016850.html">[jdom-interest] - XPath examples</link> for parameterized queries.</para> - </callout> + <callout arearefs="sda1_dom_fig_domXpathImgSearch-4-co" + xml:id="sda1_dom_fig_domXpathImgSearch-4"> + <para>Using no parameters. See <link + xlink:href="http://www.jdom.org/pipermail/jdom-interest/2012-May/016850.html">[jdom-interest] + XPath examples</link> for parameterized queries.</para> + </callout> - <callout arearefs="sda1_dom_fig_domXpathImgSearch-5-co" - xml:id="sda1_dom_fig_domXpathImgSearch-5"> - <para>Using previously defined namespace. The ellipsis in - <methodname - xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/xpath/XPathFactory.html#compile(java.lang.String,%20org.jdom2.filter.Filter,%20java.util.Map,%20org.jdom2.Namespace...)">compile</methodname> - supports multiple namespace definitions.</para> - </callout> - </calloutlist> - </figure> + <callout arearefs="sda1_dom_fig_domXpathImgSearch-5-co" + xml:id="sda1_dom_fig_domXpathImgSearch-5"> + <para>Using previously defined namespace. The ellipsis in <methodname + xlink:href="http://www.jdom.org/docs/apidocs/org/jdom2/xpath/XPathFactory.html#compile(java.lang.String,%20org.jdom2.filter.Filter,%20java.util.Map,%20org.jdom2.Namespace...)">compile</methodname> + supports multiple namespace definitions.</para> + </callout> + </calloutlist> <figure xml:id="domFindImages"> <title>Searching for images</title> @@ -1871,10 +1924,11 @@ break;</programlisting> <figure xml:id="sda1_dom_fig_domXpathVariables"> <title>Parameterized search expressions</title> - <programlisting language="java">Map<String, Object> xpathVarsNamespacePrefix = new HashMap<>(); -xpathVarsNamespacePrefix.put("cssClass", null); ...</programlisting> - - <programlisting language="none">XPathExpression<Element> searchCssClass = XPathFactory.instance().compile( + <programlisting language="none">Map<String, Object> <link + xlink:href="https://gitlab.mi.hdm-stuttgart.de/goik/GoikLectures/blob/master/P/Sda1/VerifyInternalReferences/src/main/java/dom/xpath/CheckLocalReferences.java">xpathVarsNamespacePrefix</link> = new HashMap<>(); +xpathVarsNamespacePrefix.put("cssClass", null) ; +... +XPathExpression<Element> searchCssClass = XPathFactory.instance().compile( "//html:*[@class = <emphasis role="red">$cssClass</emphasis>]", new ElementFilter(), xpathVarsNamespacePrefix, htmlNamespace);