You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2005/05/09 03:01:40 UTC

cvs commit: xml-xerces/java/samples/dom DOMGenerate.java DOM3.java Counter.java DOMAddLines.java

mrglavas    2005/05/08 18:01:40

  Modified:    java/samples/dom DOMGenerate.java DOM3.java Counter.java
                        DOMAddLines.java
  Log:
  Miscellaneous cleanup to DOM samples.
  
  Revision  Changes    Path
  1.7       +15 -14    xml-xerces/java/samples/dom/DOMGenerate.java
  
  Index: DOMGenerate.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/DOMGenerate.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DOMGenerate.java	24 Feb 2004 23:41:05 -0000	1.6
  +++ DOMGenerate.java	9 May 2005 01:01:40 -0000	1.7
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2000-2002,2004 The Apache Software Foundation.
  + * Copyright 2000-2002,2004,2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -14,18 +14,17 @@
    * limitations under the License.
    */
   
  +package dom;
   
  +import java.io.StringWriter;
   
  -package dom;
  -import  org.w3c.dom.*;
  -import  org.apache.xerces.dom.DocumentImpl;
  -import  org.apache.xerces.dom.DOMImplementationImpl;
  -import  org.w3c.dom.Document;
  -import  org.apache.xml.serialize.OutputFormat;
  -import  org.apache.xml.serialize.Serializer;
  -import  org.apache.xml.serialize.SerializerFactory;
  -import  org.apache.xml.serialize.XMLSerializer;
  -import  java.io.*;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
  +import org.apache.xml.serialize.OutputFormat;
  +import org.apache.xml.serialize.XMLSerializer;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
   
   /**
    * Simple Sample that:
  @@ -37,7 +36,10 @@
   public class DOMGenerate {
       public static void main( String[] argv ) {
           try {
  -            Document doc= new DocumentImpl();
  +            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  +            DocumentBuilder db = dbf.newDocumentBuilder();
  +            Document doc = db.newDocument();
  +            
               Element root = doc.createElement("person");     // Create Root Element
               Element item = doc.createElement("name");       // Create element
               item.appendChild( doc.createTextNode("Jeff") );
  @@ -50,7 +52,6 @@
               root.appendChild( item );                       // Attach another Element - grandaugther
               doc.appendChild( root );                        // Add Root to Document
   
  -
               OutputFormat    format  = new OutputFormat( doc );   //Serialize DOM
               StringWriter  stringOut = new StringWriter();        //Writer will be a String
               XMLSerializer    serial = new XMLSerializer( stringOut, format );
  
  
  
  1.12      +7 -8      xml-xerces/java/samples/dom/DOM3.java
  
  Index: DOM3.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/DOM3.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DOM3.java	24 Feb 2004 23:41:05 -0000	1.11
  +++ DOM3.java	9 May 2005 01:01:40 -0000	1.12
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2002,2004 The Apache Software Foundation.
  + * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -19,17 +19,16 @@
   import org.w3c.dom.DOMConfiguration;
   import org.w3c.dom.DOMError;
   import org.w3c.dom.DOMErrorHandler;
  +import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.bootstrap.DOMImplementationRegistry;
  -import org.w3c.dom.Document;
  +import org.w3c.dom.ls.DOMImplementationLS;
  +import org.w3c.dom.ls.LSOutput;
   import org.w3c.dom.ls.LSParser;
   import org.w3c.dom.ls.LSParserFilter;
  -import org.w3c.dom.ls.DOMImplementationLS;
   import org.w3c.dom.ls.LSSerializer;
   import org.w3c.dom.traversal.NodeFilter;
  -import org.w3c.dom.ls.LSOutput;
  -import org.apache.xerces.dom.DOMOutputImpl;
   
   /**
    * This sample program illustrates how to use DOM L3 
  @@ -127,7 +126,7 @@
   
               // serialize document to standard output
               //domWriter.writeNode(System.out, doc);
  -            LSOutput dOut = new DOMOutputImpl();
  +            LSOutput dOut = impl.createLSOutput();
               dOut.setByteStream(System.out);
               domWriter.write(doc,dOut);
   
  @@ -148,11 +147,11 @@
   
       public boolean handleError(DOMError error){
           short severity = error.getSeverity();
  -        if (severity == error.SEVERITY_ERROR) {
  +        if (severity == DOMError.SEVERITY_ERROR) {
               System.out.println("[dom3-error]: "+error.getMessage());
           }
   
  -        if (severity == error.SEVERITY_WARNING) {
  +        if (severity == DOMError.SEVERITY_WARNING) {
               System.out.println("[dom3-warning]: "+error.getMessage());
           }
           return true;
  
  
  
  1.13      +1 -4      xml-xerces/java/samples/dom/Counter.java
  
  Index: Counter.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/Counter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Counter.java	9 May 2005 00:38:01 -0000	1.12
  +++ Counter.java	9 May 2005 01:01:40 -0000	1.13
  @@ -22,10 +22,7 @@
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.Node;
   import org.w3c.dom.Text;
  -
   import org.xml.sax.SAXException;
  -import org.xml.sax.SAXNotRecognizedException;
  -import org.xml.sax.SAXNotSupportedException;
   import org.xml.sax.SAXParseException;
   
   /**
  
  
  
  1.11      +6 -11     xml-xerces/java/samples/dom/DOMAddLines.java
  
  Index: DOMAddLines.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/DOMAddLines.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DOMAddLines.java	24 Feb 2004 23:41:05 -0000	1.10
  +++ DOMAddLines.java	9 May 2005 01:01:40 -0000	1.11
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2002,2004 The Apache Software Foundation.
  + * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -16,28 +16,23 @@
   
   package dom;                    
   
  -import java.io.*;
  +import java.io.IOException;
  +import java.io.OutputStreamWriter;
  +import java.io.PrintWriter;
   
   import org.apache.xerces.parsers.DOMParser;
   import org.apache.xerces.xni.Augmentations;
  -import org.apache.xerces.xni.QName;
   import org.apache.xerces.xni.NamespaceContext;
  +import org.apache.xerces.xni.QName;
   import org.apache.xerces.xni.XMLAttributes;
   import org.apache.xerces.xni.XMLLocator;
   import org.apache.xerces.xni.XMLString;
   import org.apache.xerces.xni.XNIException;
  -
   import org.w3c.dom.Attr;
   import org.w3c.dom.Document;
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  -import org.w3c.dom.NamedNodeMap;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.Locator;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.helpers.*;
   
   /**
    * A sample of Adding lines to the DOM Node. This sample program illustrates:
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org