MaryDomUtils.setTokenText(t, token); tn.getParentNode().insertBefore(t, tn); currentTextNode.getParentNode().removeChild(currentTextNode); currentTextNode.getParentNode().removeChild(currentTextNode);
MaryDomUtils.setTokenText(t, token); tn.getParentNode().insertBefore(t, tn); currentTextNode.getParentNode().removeChild(currentTextNode); currentTextNode.getParentNode().removeChild(currentTextNode);
private boolean preserveWhiteSpace(Text t) { Element parent = Node.ELEMENT_NODE == t.getParentNode().getNodeType() ? (Element) t.getParentNode() : null; boolean preserveWhitespace = parent != null && "pre".equals(parent.getTagName()); // TODO(rjrjr) What about script blocks? return preserveWhitespace; } }
private boolean preserveWhiteSpace(Text t) { Element parent = Node.ELEMENT_NODE == t.getParentNode().getNodeType() ? (Element) t.getParentNode() : null; boolean preserveWhitespace = parent != null && "pre".equals(parent.getTagName()); // TODO(rjrjr) What about script blocks? return preserveWhitespace; } }
@Override public void visit(Text text) { if (text.getParentNode().equals(documentElement)) { return; } requestParameters.put(text.getParentNode().getLocalName().toUpperCase(), text.getNodeValue()); }
/** * Returns the owner element of the node and null if not found. * * @param node * @return */ public static Element getOwnerElement(Node node) { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ATTRIBUTE_NODE: return ((Attr) node).getOwnerElement(); case Node.TEXT_NODE: return (Element) ((Text) node).getParentNode(); case Node.CDATA_SECTION_NODE: return (Element) ((CDATASection) node).getParentNode(); case Node.ELEMENT_NODE: return (Element) node; } return null; }
public static void trimNode(Node node) { List<org.w3c.dom.Text> nodes=new LinkedList<org.w3c.dom.Text>(); trimNode(node,nodes); for (org.w3c.dom.Text n: nodes){ if (n.getTextContent().equals("")) n.getParentNode().removeChild(n); } }
public static void trimNode(Node node) { List<org.w3c.dom.Text> nodes=new LinkedList<org.w3c.dom.Text>(); trimNode(node,nodes); for (org.w3c.dom.Text n: nodes){ if (n.getTextContent().equals("")) n.getParentNode().removeChild(n); } }
/** * Formats a text or CDATA node for {@link #getShortString}. * * @param sb the builder to append to * @param aNode the text or CDATA node * * @since XMLUnit 2.4.0 */ protected void appendText(StringBuilder sb, Text aNode) { sb.append("<") .append(aNode.getParentNode().getNodeName()) .append(" ...>"); if (aNode instanceof CDATASection) { sb.append("<![CDATA[") .append(aNode.getNodeValue()) .append("]]>"); } else { sb.append(aNode.getNodeValue()); } sb.append("</") .append(aNode.getParentNode().getNodeName()) .append(">"); }
/** * Returns the owner element of the node and null if not found. * * @param node * @return */ public static Element getOwnerElement(Node node) { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ATTRIBUTE_NODE: return ((Attr) node).getOwnerElement(); case Node.TEXT_NODE: return (Element) ((Text) node).getParentNode(); case Node.CDATA_SECTION_NODE: return (Element) ((CDATASection) node).getParentNode(); case Node.ELEMENT_NODE: return (Element) node; } return null; }
public CMDataType getCMDataType(Text text) { CMDataType result = null; Node parentNode = text.getParentNode(); if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) { CMElementDeclaration ed = getCMElementDeclaration((Element)parentNode); result = ed.getDataType(); } return result; }
/** * @param domNode */ public static void trim(final Node domNode) { assert domNode != null; assert (Node.TEXT_NODE != domNode.getNodeType()); List<Text> removeMe = new LinkedList<Text>(); NodeList childNodes = domNode.getChildNodes(); for (Node child : nodeListToIterator(childNodes)) { if (Node.TEXT_NODE == child.getNodeType()) { if ((child.getNodeValue() == null) || child.getNodeValue().trim().isEmpty()) { removeMe.add((Text) child); } continue; } trim(child); } for (Text node : removeMe) { Node parent = node.getParentNode(); if (parent != null) { parent.removeChild(node); } } }
/** * @param domNode */ public static void trim(final Node domNode) { assert domNode != null; assert (Node.TEXT_NODE != domNode.getNodeType()); List<Text> removeMe = new LinkedList<Text>(); NodeList childNodes = domNode.getChildNodes(); for (Node child : nodeListToIterator(childNodes)) { if (Node.TEXT_NODE == child.getNodeType()) { if ((child.getNodeValue() == null) || child.getNodeValue().trim().isEmpty()) { removeMe.add((Text) child); } continue; } trim(child); } for (Text node : removeMe) { Node parent = node.getParentNode(); if (parent != null) { parent.removeChild(node); } } }
protected void runTest() throws Throwable { DocumentBuilder builder = dbf.newDocumentBuilder(); Document document = builder.newDocument(); Element parent = document.createElementNS(null, "test"); Text node = document.createTextNode("test"); parent.appendChild(node); assertSame(node, document.adoptNode(node)); assertSame(document, node.getOwnerDocument()); assertNull(node.getParentNode()); assertNull(parent.getFirstChild()); } }
protected void runTest() throws Throwable { DocumentBuilder builder = dbf.newDocumentBuilder(); Document document1 = builder.newDocument(); Document document2 = builder.newDocument(); Element parent = document1.createElementNS(null, "test"); Text node = document1.createTextNode("test"); parent.appendChild(node); assertSame(node, document2.adoptNode(node)); assertSame(document2, node.getOwnerDocument()); assertNull(node.getParentNode()); assertNull(parent.getFirstChild()); } }
/** * Replace all text values of a {@link Node} with CDATA values. * * @param doc the document to update * @param node the node to update */ public static void replaceTextWithCData(Document doc, Node node) { if (node instanceof Text) { Text text = (Text) node; CDATASection cdata = doc.createCDATASection(text.getTextContent()); Element parent = (Element) text.getParentNode(); parent.replaceChild(cdata, text); } else if (node instanceof Element) { //LOGGER.debug( "ELEMENT " + element.getTagName() ); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { //LOGGER.debug( "> " + children.item( i ).getClass().getName() ); XmlUtils.replaceTextWithCData(doc, children.item(i)); } } }
@Override public void text(String name, String type, String content) { Element element; element = (Element) Builder.textElement(parent(), name, content).getParentNode(); type(element, type); }
@Override public void text(String name, String type, String content) { Element element; element = (Element) Builder.textElement(parent(), name, content).getParentNode(); type(element, type); }
public IPropertyDescriptor createTextPropertyDescriptor(Text text) { IPropertyDescriptor result = null; Node parentNode = text.getParentNode(); if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) { Element parentElement = (Element) parentNode; ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument()); CMElementDeclaration ed = null; if (mq != null) { ed = mq.getCMElementDeclaration(parentElement); } if (ed != null) { result = createPropertyDescriptorHelper(HACK, parentElement, ed); } else { result = createDefaultPropertyDescriptor(parentElement.getNodeName()); } } if (result == null) { result = new TextPropertyDescriptor(HACK, HACK); } return result; }
startNode = (IndexedRegion) ((Text) startNode).getParentNode(); endNode = (IndexedRegion) ((Text) endNode).getParentNode();