Semaine 9


28/05/2001


getAssociatedStylesheet()
wrapper = encapsuleur, emballeuse
core = coeur, base, noyau


29/05/2001

 

Questions:

Où en est DOM2?
Quel est l'équivalent de man pour Java?
charAt?

xsl-list@lists.mulberrytech.com Mailing List Interface:
http://www.biglist.com/lists/xsl-list/archives/
Search the xsl-list@lists.mulberrytech.com Archives

B-Bop Xfinity Designer:
www.b-bop.com/products_xfinity_designer.htm
Xfinity Designer is a Visual XSL Stylesheet development tool for developers to quickly and easily generate XSL stylesheets without becoming experts at XSL and XPATH syntax.
Microsoft Windows 98, 2000, NT :-(
 

Xerces:

DOMWriter produit du code XML à partir d'un fichier XML:
personal.dtd:
<!ATTLIST person contr (true|false) 'false'>
personal.xml:
  <person id="Big.Boss">
[barkati@ceres dom]$ java dom.DOMWriter ../../data/personal.xml
  <person contr="false" id="Big.Boss">

XML canonique: pas d'en-tête, ni de retour chariot.

[barkati@ceres sax]$ java sax.SAXWriter ../../data/personal.xml
[barkati@ceres sax]$ java sax.SAX2Writer ../../data/personal.xml

DOMWriter:

DOMParserWrapper parser =
            (DOMParserWrapper)Class.forName(parserWrapperName).newInstance();

            parser.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion",
                               setDeferredDOM );
            parser.setFeature( "http://xml.org/sax/features/validation",
                               setValidation );
            parser.setFeature( "http://xml.org/sax/features/namespaces",
                               setNameSpaces );
            parser.setFeature( "http://apache.org/xml/features/validation/schema",
                               setSchemaSupport );

            Document document = parser.parse(uri);
            DOMWriter writer = new DOMWriter(canonical);
            writer.print(document);
 

SAXWriter:

            HandlerBase handler = new SAXWriter(canonical);
           Parser parser = ParserFactory.makeParser(parserName);

            if ( parser instanceof XMLReader ){
                ((XMLReader)parser).setFeature( "http://xml.org/sax/features/validation",
                                                setValidation);
                ((XMLReader)parser).setFeature( "http://xml.org/sax/features/namespaces",
                                                setNameSpaces );
                ((XMLReader)parser).setFeature( "http://apache.org/xml/features/validation/schema",
                                                setSchemaSupport );

            }

            parser.setDocumentHandler(handler);
            parser.setErrorHandler(handler);
            parser.parse(uri);
 

SAX2Writer:

            DefaultHandler handler = new SAX2Writer(canonical);
           XMLReader parser = (XMLReader)Class.forName(parserName).newInstance();

            parser.setFeature( "http://xml.org/sax/features/validation",
                                                setValidation);
            parser.setFeature( "http://xml.org/sax/features/namespaces",
                                                setNameSpaces );
            parser.setFeature( "http://apache.org/xml/features/validation/schema",
                                                setSchemaSupport );

            parser.setContentHandler(handler);
            parser.setErrorHandler(handler);
            parser.parse(uri);
 

DOMFilter:

            Document document = parser.parse(uri);
            // get elements that match
           NodeList elements = document.getElementsByTagName(elementName);
            // print nodes
            print(elements, attributeName);

[barkati@ceres dom]$ java dom.DOMFilter -e family ../../data/personal.xml
../../data/personal.xml:
<family>
<family>
<family>
<family>
<family>
<family>
[barkati@ceres dom]$ java dom.DOMFilter -a subordinates ../../data/personal.xml
../../data/personal.xml:
<link subordinates="one.worker two.worker three.worker four.worker five.worker">
 

[barkati@ceres traversal]$ java dom.traversal.IteratorView ../good.xml

IteratorView:

package dom.traversal;

import java.awt.*;
import java.awt.event.*;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import org.w3c.dom.traversal.*;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import ui.DOMTreeFull;

public class IteratorView
    extends JFrame
    implements ActionListener {

    Document document;
    TreeNode lastSelected;
    DOMParser parser;
    JTextArea messageText;
    JScrollPane messageScroll;
    DOMTreeFull jtree;
    NodeIterator iterator;
    NameNodeFilter nameNodeFilter;

            iterator = ((DocumentTraversal)document).
                createNodeIterator(
                    document,
                    NodeFilter.SHOW_ALL,
                    new NameNodeFilter(),
                    true);

        if (e.getSource() == nextButton) {
            Node node = iterator.nextNode();

        if (e.getSource() == prevButton) {
            Node node = iterator.previousNode();

            parent.removeChild(node);

            Node textNode = document.createTextNode(text);
                node.appendChild(textNode);
 

TreeWalkerView:

[barkati@ceres traversal]$ java dom.traversal.TreeWalkerView ../../../data/personal.xml

Walk Group:

Parent, Previous Sibling, Next Sibling, First Child, Last Child - call the corresponding function in TreeWalker and show the result as a selected Node.

Selected Node Group:

current - set the current node to the selected node.
remove - remove the selected node and update the tree. You must press a button to see next or previous node selection.
add - add a text node. You must press a button to see next or previous node selection.
 


30/05/2001

 

Xalan:

Xalan is an XSLT processor for transforming XML documents into HTML, text, or other XML document types. Xalan-Java version 1.2.2 is a complete and robust implementation of the W3C Recommendations for XSL Transformations (XSLT) and the XML Path Language (XPath).
Xalan can be used from the command line, in an applet or a servlet, or as a module in other program. By default, it uses the Xerces XML parser, but it can interface to any XML parser that conforms to the DOM level 2 or SAX level 1 specification.

[barkati@ceres barkati]$ tar xvzf xalan-j_1_2_2.tar.gz
It is compatible with Xerces 1.1.3
xerces-1_3_1

Acknowledgment: I have added the address
   barkati@edite-de-paris.com.fr
to the xalan-dev mailing list.
 

file:/home/barkati/xalan-j_1_2_2/docs/overview.html
Xalan-Java uses a high-performance Document Table Model (DTM) to
                     parse XML documents and XSL stylesheets.
The input may appear in the form of a file, a character stream,
                     a byte stream, a DOM, or a SAX input stream.
Xalan-Java performs the transformations specified in the XSL stylesheet and produces
                     a document file, a character stream, a byte stream, a DOM, or a series of SAX events,
                     as you specify when you set up the transformation.
 

SimpleTransform.java:

    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
    processor.process(new XSLTInputSource("birds.xml"),
                      new XSLTInputSource("birds.xsl"),
                      new XSLTResultTarget("birds.out"));
 

XSL:

  1. Transforming (rules)
  2. Formatting (Formatting Objects, XHTML -HTML en XML-)
XSL manipule la stucture logique des documents XML: filtering, sorting, searching.
XML parser + XSL processor = pattern matching in the stylesheet.

XSL processor:

begins with the root node, and generates a tree when matching.
  1. Constructing a result tree from a source tree
  2. Interpreting the result tree for formatting purposes

Namespaces:

garantee uniqueness in XML vocabularies
xmlns:prefix="NameSpace"
Le préfixe est facultatif => déclaration explicite ou ar défaut

XPath:

an expression language (non-XML) that's used to adress parts of an XML document -> XSLT
 

Place mémoire:

df
du -s


31/05/2001


Résultat de la recherche pour le mot : embedded
 scellé = embedded (adjectif, adverbe)
 truc = embedded (adjectif, adverbe)
 embedd* = embedded (n/a)
 embarqué = embedded (adjectif, adverbe)
 intégré = embedded (adjectif, adverbe)
 scelle = embedded (n/a)
 

Bibliographie:

Interfaces homme-machine et création musicale, ed. Hermes
 

Acknowledgment: I have added the address
   barkati@edite-de-paris.com.fr
to the announcements mailing list.
 

Xalan:

TransformToDom:

[barkati@ceres TransformToDom]$ java TransformToDom
 

import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessorFactory;

import org.apache.xalan.xpath.xml.TreeWalker;
import org.apache.xalan.xpath.xml.FormatterToXML;

import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

    // Create an XSLT processor.
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Create input source documents.
    XSLTInputSource xmlID = new XSLTInputSource("birds.xml");
    XSLTInputSource stylesheetID = new XSLTInputSource("birds.xsl");

    // Create a DOM Document node to attach the result nodes to.
    Document out = new org.apache.xerces.dom.DocumentImpl();
    XSLTResultTarget resultTarget = new XSLTResultTarget(out);

    // Process the source tree and produce the result tree.
    processor.process(xmlID, stylesheetID, resultTarget);

    // Use the FormatterToXML and TreeWalker to print the DOM to System.out
    FormatterToXML fl = new FormatterToXML(new FileOutputStream("birds.out"));
    TreeWalker tw = new TreeWalker(fl);
    tw.traverse(out);
 

UseStylesheetParam:

    // Set a param named "param1", that the stylesheet can obtain.
    processor.setStylesheetParam("param1", processor.createXString(args[0]));

[barkati@ceres UseStylesheetParam]$ java UseStylesheetParam aa
------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<out>aa</out>
------------------

foo.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="param1" select="'default value'"/>
  <xsl:template match="doc">
    <out><xsl:value-of select="$param1"/></out>
  </xsl:template>
</xsl:stylesheet>
 

ApplyXPath:

[barkati@ceres ApplyXPath]$ java ApplyXPath foo.xml /doc/name/@first
<output>
DavidDavidDonaldEmilyJackMyriamPaulRobertScottShane</output>

        // Use the simple XPath API to select a node.
        nl = XPathAPI.selectNodeList(root, xpath);

        // Use the FormatterToXML class right not instead of
        // the Xerces Serializer classes, because I'm not sure
        // yet how to make them handle arbitrary nodes.
        FormatterToXML fl = new FormatterToXML(System.out);
        TreeWalker tw = new TreeWalker(fl);
        int n = nl.getLength();
        for(int i = 0; i < n; i++)
        {
          tw.traverse(nl.item(i));
          // We have to do both a flush and a flushWriter here,
          // because the FormatterToXML rightly does not flush
          // until it get's an endDocument, which usually will
          // not happen here.
          fl.flush();
          fl.flushWriter();
 

Pipe:

[barkati@ceres Pipe]$ java Pipe
<?xml version="1.0" encoding="ISO-8859-1"?>
<out>Hello ...and goodby!</out>[barkati@ceres Pipe]$

foo.xml:
<?xml version="1.0"?>
<doc>Hello</doc>

foo.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="doc">
    <out><xsl:value-of select="."/></out>
  </xsl:template>
</xsl:stylesheet>

foo2.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="out">
    <out><xsl:value-of select="."/> ...and goodby!</out>
  </xsl:template>
</xsl:stylesheet>
 
 
 

XSL:

Full-featured query language for XML. xsl:stylesheet
xsl:template match="/" //single != multiple templates
xsl:value-of //insert the value of an element or attribute in the resulting ouput
xsl:if //match
xsl:for-each //order-by, select
xsl:apply-templates //order-by, select

<?xml-stylesheet href="Vehicles.xsl" type="text/xsl"?> //in the XML file
select=@attribute
 

birds.xsl:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>

<xsl:template match="Class">
<BirdInfo>
 <xsl:apply-templates select="Order"/>
</BirdInfo>
</xsl:template>

<xsl:template match="Order">
Order is:  <xsl:value-of select="@Name"/>
 <xsl:apply-templates select="Family"/><xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="Family">
 Family is:  <xsl:value-of select="@Name"/>
 <xsl:apply-templates select="Species | SubFamily | text()"/>
</xsl:template>

<xsl:template match="SubFamily">
  SubFamily is <xsl:value-of select="@Name"/>
    <xsl:apply-templates select="Species | text()"/>
</xsl:template>

<xsl:template match="Species">
 <xsl:choose>
   <xsl:when test="name(..)='SubFamily'">
  <xsl:text> </xsl:text><xsl:value-of select="."/><xsl:text> </xsl:text><xsl:value-of select="@Scientific_Name"/>
   </xsl:when>
   <xsl:otherwise>
  <xsl:value-of select="."/><xsl:text> </xsl:text><xsl:value-of select="@Scientific_Name"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

</xsl:stylesheet>
 

Objet:               Re: DOM tree
        Date:               Thu, 31 May 2001 15:45:34 +0200 (CEST)
          De:               René Jensen <lundeman@tbkol.dk>
 Répondre-A:               xerces-j-user@xml.apache.org
           A:               xerces-j-user@xml.apache.org
  Références:               1

Citat manuel.paitreault@cnedi69.cnafmail.fr:

> Hi,
>
> I create a DOM tree with xerces from a XML file :
>
>      DOMParser parser = new DOMParser();
>           try           {
>           parser.parse("file.xml");
>           }         catch (SAXException se)          {
>           se.printStackTrace();
>           }
>      Document RequeteXML = parser.getDocument();
>      NodeList NL = RequeteXML.getElementsByTagName("Mot");
> etc .....................
>
> I do some works on this tree ... I add and remove Nodes etc ...
> btu I know, I'd like to make the reverse operation : I'd like to transform
> my Domtree "Document RequeteXML" in a file "requeteXML.xml" on my hard disk
> ... is it possible, and how can I do this ??
>
> thank you in advance !!
>

  XMLSerializer mySerializer =
      new XMLSerializer("SomeOutPutSource","SomeFormatter");
  mySerializer.serialize(RequeteXML);

Check the javaDoc for further details

         \\|//
         (@ @)
-----oOOo-(_)-oOOo-----
      René Jensen
   lundeman@tbkol.dk


01/06/2001

 

 
 
 

Acknowledgment: I have added the address
   barkati@edite-de-paris.com.fr
to the announcements mailing list.