public static org.w3c.dom.Document xomToDom(Element elem) { try { elem = (Element)elem.copy(); return DOMConverter.convert(new Document(elem), DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation()); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
public Element deepClone() { return new Element((nu.xom.Element) xomElement.copy()); } }
public Element deepClone() { return new Element((nu.xom.Element) xomElement.copy()); } }
public static Element stringToXml(String xml) { if(xml == null) return null; try { Document doc = PARSER.build(new StringReader(xml)); Element elm = doc.getRootElement(); return (Element) elm.copy(); } catch (Exception e) { throw new RuntimeException(e); } }
public static String xmlToString(Element elm) { // TODO ugly hack to retain namespaces return new Document((Element) elm.copy()).toXML().replaceFirst("<.+>", ""); }
private KSBrandAppender( final Optional<Element> in_brand_top, final Optional<Element> in_brand_bottom) { this.brand_start = NullCheck.notNull(in_brand_top); this.brand_end = NullCheck.notNull(in_brand_bottom); this.appender_start = (e) -> { if (this.brand_start.isPresent()) { e.insertChild(this.brand_start.get().copy(), 0); } }; this.appender_end = (e) -> { if (this.brand_end.isPresent()) { e.insertChild(this.brand_end.get().copy(), 0); } }; }
/** * write XML for an element node. copies elements so it doesn't have a * document parent * * @param elem * @return the XML String */ public String getXML(Element elem) { Element clone = (Element) elem.copy(); Document doc = new Document(clone); return getXML(doc); }
public static Node createNode(String xmlDefintion) { Node node = null; try { node = builder2.build(new StringReader(xmlDefintion)).getRootElement().copy(); } catch (ValidityException e) { e.printStackTrace(); } catch (ParsingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return node; }
public static ImmutableList<Element> getChildren(HasTMMetadata fromEntity) { try { String metadataString = fromEntity.getMetadata(TMMetadataType.TMX14); if (metadataString == null) { return ImmutableList.of(); } @SuppressWarnings("unchecked") Map<String, Object> metadata = jsonMapper.readValue(metadataString, Map.class); List<String> children = getChildrenXml(metadata); Builder<Element> result = ImmutableList.builder(); for (String childXml : children) { Document doc = new nu.xom.Builder().build(childXml, null); Element elem = (Element) doc.getRootElement().copy(); result.add(elem); } return result.build(); } catch (Exception e) { // error parsing XML or json, which "shouldn't happen" throw new RuntimeException(e); } }
/** * Supported children are currently {@code <prop>} and {@code <note>}. * * @param child * @param childrenXml */ private static void addChildIfSupported(Element child, Builder<String> childrenXml) { String uri = child.getNamespaceURI(); String name = child.getLocalName(); if (inTmxNamespace(uri) && (name.equals("prop") || name.equals("note"))) { Element copy = (Element) child.copy(); copy.setNamespacePrefix(""); copy.setNamespaceURI(""); childrenXml.add(copy.toXML()); } }
/** * Utility method that allows for convenient conversion of * <a href="http://www.cafeconleche.org/XOM/apidocs/index.html">XOM</a> elements to * CML elements if necessary. * always makes a copy * * @param xml a valid CMLElement * @return the {@link CMLElement} */ public static CMLElement ensureCML(Element xml) { if (xml == null) { throw new RuntimeException("null cml"); } if (xml instanceof CMLElement) { return (CMLElement) xml.copy(); } else { Document doc = new Document((Element) xml.copy()); try { Document doc2 = new CMLBuilder().build(doc.toXML(), doc.getBaseURI()); CMLElement cmlElement = (CMLElement) doc2.getRootElement(); return cmlElement; } catch (Exception e) { CMLUtil.debug(xml, "ensureCMLProblem "+e); throw new RuntimeException("ensureCMLProblem", e); } } }
@Override public void onBodyEnd( final Element body) { if (inserts.getBodyEnd().isSome()) { final Some<Element> some = (Some<Element>) inserts.getBodyEnd(); body.appendChild(some.get().copy()); } }
Element elm = (Element) doc.getRootElement().copy(); for(Field attrField : field.getFields()) { String ns = attrField.getNamespace();
@Override public @Nullable Element onBodyStart( final Element body) { if (inserts.getBodyStart().isSome()) { final Some<Element> some = (Some<Element>) inserts.getBodyStart(); body.appendChild(some.get().copy()); } return null; }