1 16 package com.google.gwt.xml.client; 17 18 import com.google.gwt.xml.client.impl.XMLParserImpl; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 27 public class XMLParser { 28 29 private static final XMLParserImpl impl = XMLParserImpl.getInstance(); 30 31 36 public static Document createDocument() { 37 return impl.createDocument(); 38 } 39 40 47 public static Document parse(String contents) { 48 return impl.parse(contents); 49 } 50 51 58 public static void removeWhitespace(Node n) { 59 removeWhitespaceInner(n, null); 60 } 61 62 69 public static boolean supportsCDATASection() { 70 return impl.supportsCDATASection(); 71 } 72 73 76 private static void removeWhitespaceInner(Node n, Node parent) { 77 if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) { 79 Text t = (Text) n; 80 if (t.getData().matches("[ \t\n]*")) { 81 parent.removeChild(t); 82 } 83 } 84 if (n.hasChildNodes()) { 85 int length = n.getChildNodes().getLength(); 86 List toBeProcessed = new ArrayList (); 87 for (int i = 0; i < length; i++) { 90 toBeProcessed.add(n.getChildNodes().item(i)); 91 } 92 for (Iterator iter = toBeProcessed.iterator(); iter.hasNext();) { 95 Node childNode = (Node) iter.next(); 96 removeWhitespaceInner(childNode, n); 97 } 98 } 99 } 100 101 104 private XMLParser() { 105 } 106 107 } 108 | Popular Tags |