Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/griffin/util/XmlUtil.java


1   /*
2    * XmlUtil.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.griffin.util;
11  
12  import java.io.*;
13  
14  import org.w3c.dom.Node;
15  
16  import javax.xml.transform.Transformer;
17  import javax.xml.transform.TransformerFactory;
18  import javax.xml.transform.dom.DOMSource;
19  import javax.xml.transform.stream.StreamResult;
20  import javax.xml.transform.TransformerException;
21  import javax.xml.transform.TransformerConfigurationException;
22  
23  
24  /**
25   * <p>Utility class for common functions.</p>
26   *
27   * @author Scott Milne
28   *
29   */
30  
31  public class XmlUtil
32  {
33    /**
34     * Extracts all data from the given node, and converts it into a String.
35     *
36     * @param  Node              A <code>org.w3c.dom.Node</code> instance.
37     *
38     * @return                  The string representation of the given {@link Node}.
39     *
40     */
41  
42    public static String ViewNode( Node node )
43    {
44      try
45      {
46        DOMSource source = new DOMSource(node);
47  
48        TransformerFactory factory = TransformerFactory.newInstance();
49        Transformer transformer = factory.newTransformer();
50  
51        StringWriter writer = new StringWriter();
52        StreamResult result = new StreamResult(writer);
53  
54        transformer.transform( source, result );
55  
56        return writer.toString();
57      }
58      catch( TransformerConfigurationException e )
59      {
60        e.printStackTrace();
61      }
62      catch( TransformerException e )
63      {
64        e.printStackTrace();
65      }
66  
67      return null;
68    }
69  }
70