/** * 复制from下的所有节点(包括Attribute, Element, Text)到to * * @param from * @param to */ public static void deepCopyElement(Element from, Element to) { if(from == null || to == null) { return; } List<Node> lNode = from.selectNodes("@*|node()"); for(Node node : lNode) { if(node instanceof Attribute) { Attribute attr = (Attribute)node; to.addAttribute(attr.getName(), attr.getText()); } else if(node instanceof Element) { Element ele = (Element)node; to.add(ele.createCopy()); } else if(node instanceof Text) { to.setText(node.getText()); } } }
private void renderAllChildNodes(final Element el) throws Exception { if (el.isTextOnly()) { renderTextToContainer(el.getText()); } else { for (Iterator< ? > it = el.nodeIterator(); it.hasNext();) { Node nFilho = (Node) it.next(); if (nFilho instanceof Text) { renderTextToContainer(nFilho.getText()); } else if (nFilho instanceof Element) { render((Element) nFilho); } } } }
public void visit(Node node) { int type = node.getNodeType(); switch (type) { case Node.ELEMENT_NODE: visit((Element) node); break; case Node.TEXT_NODE: visit((Text) node); break; case Node.CDATA_SECTION_NODE: visit((CDATA) node); break; default: push(null); } }
@Override public void visit(Text node) { Text text = node; if (skipEmptyTextNode && text.getText().trim().isEmpty()) push(null); else { StringValue obj = (StringValue) getObjectRepo().createObject( ObjectType.STRING, ObjectScope.ExecutionContext); String name = text.getNodeTypeName(); obj.setName(name); obj.setValue(text.getText()); push(obj); } }
public String getCollectionKeyFromDDS( String _collectionName ) { String collectionKey = null; // make the call to DDS and get ListCollections try { URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=ListCollections" ).openConnection(); connection.setDoOutput( true ); connection.setDoInput(true); ((HttpURLConnection)connection).setRequestMethod("GET"); Map<String,String> uris = new HashMap<String,String>(); uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" ); uris.put( "ddswsnews", "http://www.dlese.org/Metadata/ddswsnews" ); uris.put( "groups", "http://www.dlese.org/Metadata/groups/" ); uris.put( "adn", "http://adn.dlese.org" ); uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" ); XPath xpath = DocumentHelper.createXPath( "//collections/collection[vocabEntry=\"" + _collectionName + "\"]/searchKey/text()" ); xpath.setNamespaceURIs( uris ); SAXReader xmlReader = new SAXReader(); this.document = xmlReader.read(connection.getInputStream()); Text t = ((Text)xpath.selectSingleNode(this.document)); collectionKey = t.getStringValue(); } catch ( Exception e ) { e.printStackTrace(); } return collectionKey; }
public void assertNodesEqual( Node n1, Node n2 ) { int nodeType1 = n1.getNodeType(); int nodeType2 = n2.getNodeType(); assertTrue( "Nodes are of same type: ", nodeType1 == nodeType2 ); switch (nodeType1) { case Node.ELEMENT_NODE: assertNodesEqual((Element) n1, (Element) n2); break; case Node.DOCUMENT_NODE: assertNodesEqual((Document) n1, (Document) n2); break; case Node.ATTRIBUTE_NODE: assertNodesEqual((Attribute) n1, (Attribute) n2); break; case Node.TEXT_NODE: assertNodesEqual((Text) n1, (Text) n2); break; case Node.CDATA_SECTION_NODE: assertNodesEqual((CDATA) n1, (CDATA) n2); break; case Node.ENTITY_REFERENCE_NODE: assertNodesEqual((Entity) n1, (Entity) n2); break; case Node.PROCESSING_INSTRUCTION_NODE: assertNodesEqual((ProcessingInstruction) n1, (ProcessingInstruction) n2); break; case Node.COMMENT_NODE: assertNodesEqual((Comment) n1, (Comment) n2); break; case Node.DOCUMENT_TYPE_NODE: assertNodesEqual((DocumentType) n1, (DocumentType) n2); break; case Node.NAMESPACE_NODE: assertNodesEqual((Namespace) n1, (Namespace) n2); break; default: assertTrue( "Invalid node types. node1: " + n1 + " and node2: " + n2, false ); } }
public void add(Text text) { element.add( text ); }
public boolean remove(Text text) { return element.remove( text ); }
default Text text(final String string) { return DocumentHelper.createText(string); }
public void add(Text text) { target().add( text ); }
public boolean remove(Text text) { return target().remove( text ); }
public boolean isText(Object obj) { return ( obj instanceof Text || obj instanceof CDATA ); }
/** * Writes the given {@link Text}. * * @param text * <code>Text</code> to output. * * @throws IOException * DOCUMENT ME! */ public void write(Text text) throws IOException { writeString(text.getText()); if (autoFlush) { flush(); } }