Source code: diffxml/fmes/PrintXML.java
1 /*
2 Class to print some XML stuff if we need
3
4 Copyright (C) 2002 Adrian Mouat
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 Author: Adrian Mouat
21 email: amouat@postmaster.co.uk
22 */
23
24 package diffxml.fmes;
25
26 import java.io.File;
27 import org.w3c.dom.Node;
28 import org.w3c.dom.NamedNodeMap;
29 import org.w3c.dom.NodeList;
30
31 public class PrintXML
32 {
33 public static void print(Node n)
34 {
35 //Do different things depending on type of node
36
37 switch (n.getNodeType())
38 {
39 case Node.TEXT_NODE :
40 System.out.println(n.getNodeValue());
41 break;
42
43 case Node.ATTRIBUTE_NODE :
44 System.out.println(n.getNodeName() + " " + n.getNodeValue());
45 break;
46
47 case Node.ELEMENT_NODE :
48 System.out.println(n.getNodeName());
49 //Print out any attributes
50 NamedNodeMap att=n.getAttributes();
51 if (att!=null)
52 {
53 System.out.println("Attributes:");
54 for(int i=0; i<att.getLength(); i++)
55 print(att.item(i));
56 }
57 //Print out any text node children
58 /*
59 NodeList cdr=n.getChildNodes();
60 if (cdr!=null)
61 {
62 System.out.println("Text Nodes:");
63 for(int i=0; i<cdr.getLength(); i++)
64 {
65 if (cdr.item(i).getNodeType()==Node.TEXT_NODE)
66 print(cdr.item(i));
67 }
68 }
69 */
70 break;
71 default: //Dont care
72 }
73 }
74 }