/** * This method removes all <code>Text</code> nodes which are made up of only * white space. * * @param n the node which is to have all of its whitespace descendents * removed. */ public static void removeWhitespace(Node n) { removeWhitespaceInner(n, null); }
public Node getFirstChild() { return getChildNodes().item(0); }
public Node getLastChild() { return getChildNodes().item(getChildNodes().getLength() - 1); }
private static void removeWhitespaceInner(Node n, Node parent) { // This n is removed from the parent if n is a whitespace node if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) { Text t = (Text) n; if (t.getData().matches("[ \t\n]*")) { parent.removeChild(t); } } if (n.hasChildNodes()) { int length = n.getChildNodes().getLength(); List<Node> toBeProcessed = new ArrayList<Node>(); // We collect all the nodes to iterate as the child nodes will change // upon removal for (int i = 0; i < length; i++) { toBeProcessed.add(n.getChildNodes().item(i)); } // This changes the child nodes, but the iterator of nodes never changes // meaning that this is safe for (Node childNode : toBeProcessed) { removeWhitespaceInner(childNode, n); } } }
private Node getNodeByTagName( Element element, String tagName ) { NodeList list = element.getChildNodes(); for ( int i = 0; i < list.getLength(); i++ ) { Node node = list.item( i ); if ( node != null && node.getNodeName().equals( tagName ) ) { return node; } } return null; }
@Override public void setText(final String text) { // TODO: remove ALL children? final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node child = nodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) { element.removeChild(child); } } if (!Strings.isNullOrEmpty(text)) { element.appendChild(document.createTextNode(text)); } }
@Override public String getText() { final StringBuilder result = new StringBuilder(); final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node child = nodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) result.append(child.getNodeValue()); } return result.toString(); }
private boolean isQueryable(Node layerNode) { NamedNodeMap attributes = layerNode.getAttributes(); Node q = attributes.getNamedItem("queryable"); if (q != null) { return "1".equals(q.getNodeValue()); } return false; }
@Override protected Element stringToElement( String xml ) { return XMLParser.parse( xml ).getDocumentElement(); }
protected XMLPacketImplGWT(final String name, @Nullable final String namespace) { document = XMLParser.createDocument(); element = document.createElement(name); if (namespace != null) { element.setAttribute("xmlns", namespace); } document.appendChild(element); }
protected boolean hasAttribute(Node node, String name) { return node.hasAttributes() && node.getAttributes().getNamedItem(name) != null; }
private String getNodeValueByTagName( Node node, String tagName ) { if ( node != null && node.getFirstChild() != null ) { return node.getFirstChild().getNodeValue(); } else { return null; } }
protected void parse(Node node) { NamedNodeMap attributes = node.getAttributes(); type = getValueRecursive(attributes.getNamedItem("xlink:type")); xLink = getValueRecursive(attributes.getNamedItem("xmlns:xlink")); href = getValueRecursive(attributes.getNamedItem("xlink:href")); } }
/** * Constructor for an empty document. * * @param mediaType * The representation's media type. */ public XmlRepresentation(MediaType mediaType) { super(mediaType); this.dom = XMLParser.createDocument(); }
@Override protected Element getFirstChildElement( Element parent ) { Node node = parent.getFirstChild(); while( node != null && !( node instanceof Element )) { node = node.getNextSibling(); } return (Element) node; }
@Override protected Element getNextSiblingElement( Element element ) { Node node = element.getNextSibling(); while( node != null && !( node instanceof Element )) { node = node.getNextSibling(); } return (Element) node; }
private Node getNodeByTagName( Element element, String tagName ) { NodeList list = element.getChildNodes(); for ( int i = 0; i < list.getLength(); i++ ) { Node node = list.item( i ); if ( node != null && node.getNodeName().equals( tagName ) ) { return node; } } return null; }
private boolean isQueryable(Node layerNode) { NamedNodeMap attributes = layerNode.getAttributes(); Node q = attributes.getNamedItem("queryable"); if (q != null) { return "1".equals(q.getNodeValue()); } return false; }
/** * This method removes all <code>Text</code> nodes which are made up of only * white space. * * @param n the node which is to have all of its whitespace descendents * removed. */ public static void removeWhitespace(Node n) { removeWhitespaceInner(n, null); }
/** * This method removes all <code>Text</code> nodes which are made up of only * white space. * * @param n the node which is to have all of its whitespace descendents * removed. */ public static void removeWhitespace(Node n) { removeWhitespaceInner(n, null); }