private String getText(Element element) { StringBuilder sb = new StringBuilder(); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node child = nodes.item(i); switch (child.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: CharacterData cdata = (CharacterData) child; sb.append(cdata.getData()); break; case Node.ENTITY_REFERENCE_NODE: EntityReference ref = (EntityReference) child; sb.append(ref.getNodeValue()); break; } } return sb.toString(); } }
private String getTextContents(Node parent) { NodeList children = parent.getChildNodes(); if (children.getLength() == 1) { return children.item(0).getNodeValue().trim(); } StringBuffer s = new StringBuffer(); Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) { String reference = ((EntityReference) child).getNodeValue(); if (reference == null && child.getNodeName() != null) { reference = "&" + child.getNodeName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } if (reference != null) { s.append(reference.trim()); } } else { s.append(child.getNodeValue().trim()); } child = child.getNextSibling(); } return s.toString().trim(); }
static String getContainedText(Node parent) { NodeList children = parent.getChildNodes(); if (children.getLength() == 1) { return children.item(0).getNodeValue().trim(); } StringBuffer s = new StringBuffer(); Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) { String reference = ((EntityReference) child).getNodeValue(); if (reference == null && child.getNodeName() != null) { reference = "&" + child.getNodeName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } if (reference != null) { s.append(reference.trim()); } } else { s.append(child.getNodeValue().trim()); } child = child.getNextSibling(); } return s.toString().trim(); }
protected String getContainedText(Node parent) { NodeList children = parent.getChildNodes(); if (children.getLength() == 1) { return children.item(0).getNodeValue().trim(); } StringBuffer s = new StringBuffer(); Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) { String reference = ((EntityReference) child).getNodeValue(); if (reference == null && child.getNodeName() != null) { reference = "&" + child.getNodeName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ } if (reference != null) { s.append(reference.trim()); } } else { s.append(child.getNodeValue().trim()); } child = child.getNextSibling(); } return s.toString().trim(); }
protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); EntityReference entref = document.createEntityReference("myentity"); assertEquals(Node.ENTITY_REFERENCE_NODE, entref.getNodeType()); assertEquals("myentity", entref.getNodeName()); assertNull(entref.getNodeValue()); assertSame(document, entref.getOwnerDocument()); } }
public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing) throws XMLStreamException { if ( n instanceof Element ) { writeElement((Element)n, writer, repairing); } else if ( n instanceof Text ) { writer.writeCharacters(((Text) n).getNodeValue()); } else if ( n instanceof CDATASection ) { writer.writeCData(((CDATASection) n).getData()); } else if ( n instanceof Comment ) { writer.writeComment(((Comment) n).getData()); } else if ( n instanceof EntityReference ) { writer.writeEntityRef(((EntityReference)n).getNodeValue()); } else if ( n instanceof ProcessingInstruction ) { ProcessingInstruction pi = (ProcessingInstruction) n; writer.writeProcessingInstruction(pi.getTarget(), pi.getData()); } }
break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE:
break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE:
break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE:
break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE:
break; case Node.ENTITY_REFERENCE_NODE: writer.writeEntityRef(((EntityReference)n).getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE:
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; EntityReference newEntRefNode; String entRefValue; String entRefName; int entRefType; doc = (Document) load("staff", true); newEntRefNode = doc.createEntityReference("ent1"); assertNotNull("createdEntRefNotNull", newEntRefNode); entRefValue = newEntRefNode.getNodeValue(); assertNull("value", entRefValue); entRefName = newEntRefNode.getNodeName(); assertEquals("name", "ent1", entRefName); entRefType = (int) newEntRefNode.getNodeType(); assertEquals("type", 5, entRefType); } /**