axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils XMLUtils.java
Date Wed, 23 May 2001 17:24:52 GMT
gdaniels    01/05/23 10:24:50

  Modified:    java/src/org/apache/axis/utils XMLUtils.java
  Log:
  Omit the XML declaration when outputting Elements.
  
  Revision  Changes    Path
  1.8       +20 -9     xml-axis/java/src/org/apache/axis/utils/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLUtils.java	2001/05/23 16:15:19	1.7
  +++ XMLUtils.java	2001/05/23 17:24:44	1.8
  @@ -56,6 +56,7 @@
   package org.apache.axis.utils ;
   
   import java.io.* ;
  +import java.util.Properties;
   import org.w3c.dom.* ;
   import javax.xml.parsers.* ;
   import javax.xml.transform.*;
  @@ -180,20 +181,18 @@
         }
     }
     
  -  public static String DocumentToString(Document doc) {
  -      return ElementToString(doc.getDocumentElement());
  -  }
  -
  -  public static void DocumentToStream(Document doc, OutputStream out) {
  -      ElementToStream(doc.getDocumentElement(), out);
  -  }
  -
  -  public static String ElementToString(Element element) {
  +  private static String privateElementToString(Element element,
  +                                               boolean omitXMLDecl)
  +  {
         try {
           StringWriter sw = new StringWriter();
           DOMSource source = new DOMSource(element);
           StreamResult result = new StreamResult(sw);
           Transformer transformer = getTransformer();
  +        Properties p = new Properties();
  +        p.put(OutputKeys.OMIT_XML_DECLARATION,
  +              omitXMLDecl ? "yes" : "no");
  +        transformer.setOutputProperties(p);
           transformer.transform(source, result);
           sw.close();
           return sw.toString();
  @@ -202,6 +201,18 @@
             e.printStackTrace();
         }
         return( null );
  +  }
  +  
  +  public static String DocumentToString(Document doc) {
  +      return privateElementToString(doc.getDocumentElement(), false);
  +  }
  +
  +  public static void DocumentToStream(Document doc, OutputStream out) {
  +      ElementToStream(doc.getDocumentElement(), out);
  +  }
  +
  +  public static String ElementToString(Element element) {
  +      return privateElementToString(element, true);
     }
     
     public static void ElementToStream(Element element, OutputStream out) {
  
  
  

Mime
View raw message