public String toXML() { return xomElement.toXML(); }
public String toXML() { return xomElement.toXML(); }
private void init(Element element) { init(element.toXML(), element); }
import nu.xom.*; import java.io.StringReader; public class XomElementAsString { public static void main( final String ... args ) throws Exception { String from = "<time><day type=\"tt\">ok</day></time>"; Builder parser = new Builder(); Document document = parser.build( new StringReader( from ) ); Element child = document .getRootElement() .getFirstChildElement( "day" ); System.out.println( child.toXML() ); } }
@Override public void processList(IContext context, Object instance, RowAdapter row, IResultSet result, List<Object> list) throws Exception { if (list.isEmpty()) { addError(context, row, result, new PluginException("None element found. XML:" + row.getElement().toXML())); return; } if (list.size() > 1) { addError(context, row, result, new PluginException("More than one element found. XML:" + row.getElement().toXML())); return; } Object base = list.get(0); if (base == null) { addError(context, row, result, new PluginException("This item is not present in object repository. XML:" + row.getElement().toXML())); } else { perform(context, base, instance, row, result); } }
@Test public void buildElementStartElementXMLEventReader() throws Exception { XMLEventReader reader = xif.createXMLEventReader(is); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (event.isStartElement() && event.asStartElement().getName().getLocalPart() .equals("tu")) { ElementBuilder.buildElement(event.asStartElement(), reader) .toXML(); } } }
@Test public void buildElementXMLStreamReader() throws Exception { XMLStreamReader reader = xif.createXMLStreamReader(is); while (reader.hasNext()) { int eventType = reader.next(); if (eventType == START_ELEMENT && reader.getLocalName().equals("tu")) { ElementBuilder.buildElement(reader).toXML(); } } }
/** * 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()); } }
/** * Sets all the TUV's metadata (attributes and children) * * @throws TMXParseException */ public static void setMetadata(TransMemoryUnitVariant toTuv, Element fromTuvElem) throws TMXParseException { Map<String, Object> metadata = buildMetadata(fromTuvElem); String lang = (String) metadata.remove(XML_LANG); if (lang != null) { toTuv.setLanguage(getValidLang(lang)); } else { throw new TMXParseException( "missing xml:lang in tuv: " + fromTuvElem.toXML()); } setSharedMetadata(toTuv, metadata); }
@Test @Ignore public void buildElementXMLStreamReaderTransformer() throws Exception { // Nasty way to ensure that we get a Transformer which supports // StAXSource: System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); Transformer t = TransformerFactory.newInstance().newTransformer(); XMLStreamReader reader = xif.createXMLStreamReader(is); while (reader.hasNext()) { int eventType = reader.next(); if (eventType == START_ELEMENT && reader.getLocalName().equals("tu")) { ElementBuilder.buildElement(reader, t).toXML(); } } } }
public void testAddsContentTypeMetadataIfMissing() throws Exception { metadataCreator.beforeParsing(document); assertEquals("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML()); }
@Override public void processList(IContext context, Object instance, RowAdapter row, IResultSet result, List<Object> list) throws Exception { if (list.isEmpty()) { for (int i = 0; i < row.getCellsCount(); i++) { result.addResult(Success.INSTANCE, context.newBlock(row.getCell(i).getElement(), this)); } } else { Exception e = new PluginException("Element found in object repository. XML:" + row.getElement().toXML()); for (int i = 0; i < row.getCellsCount(); i++) { result.addResult(i == 0 ? Failure.INSTANCE : Warning.INSTANCE, context.newBlock(row.getCell(i).getElement(), this), i == 0 ? e : null); } } } }
public String process(String html) { Element rootElement = new TestRig() .process(html) .getXOMDocument() .getRootElement(); removeIrrelevantElements(rootElement); return rootElement.toXML(); }
public void testDoesNotAddContentTypeMetadataIfAlreadyPresent() throws Exception { Element meta = new Element("meta"); meta.addAttribute(new Attribute("http-equiv", "Content-Type")); meta.addAttribute(new Attribute("content", "text/html; charset=UTF-8")); head.appendChild(new Element(meta)); assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML()); metadataCreator.beforeParsing(document); assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML()); } }
public String process(String html) { Element rootElement = new TestRig() .process(html) .getXOMDocument() .getRootElement(); removeIrrelevantElements(rootElement); return rootElement.toXML(); }
@Test // See Issue 26 public void xmlOutputContainsAnExplicitEndTagForScriptElement() { JavaScriptLinker javaScriptLinker = new JavaScriptLinker(NOT_NEEDED_PARAMETER); Element html = new Element("html"); Element head = new Element("head"); html.appendChild(head); javaScriptLinker.beforeParsing(new Document(html)); assertEquals("<head><script type=\"text/javascript\"></script></head>", head.toXML()); } }
public static IChemModel roundTripChemModel(Convertor convertor, IChemModel model) throws Exception { String cmlString = "<!-- failed -->"; Element cmlDOM = convertor.cdkChemModelToCMLList(model); cmlString = cmlDOM.toXML(); logger.debug("CML string: ", cmlString); CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); reader.close(); IChemFile file = (IChemFile) reader.read(model.getBuilder().newInstance(IChemFile.class)); Assert.assertNotNull(file); Assert.assertEquals(1, file.getChemSequenceCount()); IChemSequence sequence = file.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); return chemModel; }
public static IReaction roundTripReaction(Convertor convertor, IReaction reaction) throws Exception { String cmlString = "<!-- failed -->"; Element cmlDOM = convertor.cdkReactionToCMLReaction(reaction); cmlString = cmlDOM.toXML(); IReaction roundTrippedReaction = null; logger.debug("CML string: ", cmlString); CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); IChemFile file = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); Assert.assertNotNull(file); Assert.assertEquals(1, file.getChemSequenceCount()); IChemSequence sequence = file.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); IReactionSet reactionSet = chemModel.getReactionSet(); Assert.assertNotNull(reactionSet); Assert.assertEquals(1, reactionSet.getReactionCount()); roundTrippedReaction = reactionSet.getReaction(0); Assert.assertNotNull(roundTrippedReaction); return roundTrippedReaction; }
public void testTransfersEverythingBeforeBodyIntoNewlyCreatedHead() throws Exception { Element style1 = new Element("style1"); Element style2 = new Element("style2"); html.appendChild(style1); html.appendChild(style2); Element body = new Element("body"); body.appendChild("some "); Element bold = new Element("b"); bold.appendChild("bold text"); body.appendChild(bold); html.appendChild(body); improver.beforeParsing(document); assertEquals("<html><head><style1 /><style2 /></head><body>some <b>bold text</b></body></html>", html.toXML()); }