nu.xom.Element.toXML()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(336)

本文整理了Java中nu.xom.Element.toXML()方法的一些代码示例,展示了Element.toXML()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.toXML()方法的具体详情如下:
包路径:nu.xom.Element
类名称:Element
方法名:toXML

Element.toXML介绍

暂无

代码示例

代码示例来源:origin: concordion/concordion

  1. public String toXML() {
  2. return xomElement.toXML();
  3. }

代码示例来源:origin: org.concordion/concordion

  1. public String toXML() {
  2. return xomElement.toXML();
  3. }

代码示例来源:origin: edu.stanford.nlp/corenlp

  1. private void init(Element element) {
  2. init(element.toXML(), element);
  3. }

代码示例来源:origin: stackoverflow.com

  1. import nu.xom.*;
  2. import java.io.StringReader;
  3. public class XomElementAsString
  4. {
  5. public static void main( final String ... args ) throws Exception
  6. {
  7. String from = "<time><day type=\"tt\">ok</day></time>";
  8. Builder parser = new Builder();
  9. Document document = parser.build( new StringReader( from ) );
  10. Element child = document
  11. .getRootElement()
  12. .getFirstChildElement( "day" );
  13. System.out.println( child.toXML() );
  14. }
  15. }

代码示例来源:origin: org.specrunner/specrunner-objects

  1. @Override
  2. public void processList(IContext context, Object instance, RowAdapter row, IResultSet result, List<Object> list) throws Exception {
  3. if (list.isEmpty()) {
  4. addError(context, row, result, new PluginException("None element found. XML:" + row.getElement().toXML()));
  5. return;
  6. }
  7. if (list.size() > 1) {
  8. addError(context, row, result, new PluginException("More than one element found. XML:" + row.getElement().toXML()));
  9. return;
  10. }
  11. Object base = list.get(0);
  12. if (base == null) {
  13. addError(context, row, result, new PluginException("This item is not present in object repository. XML:" + row.getElement().toXML()));
  14. } else {
  15. perform(context, base, instance, row, result);
  16. }
  17. }

代码示例来源:origin: zanata/zanata-platform

  1. @Test
  2. public void buildElementStartElementXMLEventReader() throws Exception {
  3. XMLEventReader reader = xif.createXMLEventReader(is);
  4. while (reader.hasNext()) {
  5. XMLEvent event = reader.nextEvent();
  6. if (event.isStartElement()
  7. && event.asStartElement().getName().getLocalPart()
  8. .equals("tu")) {
  9. ElementBuilder.buildElement(event.asStartElement(), reader)
  10. .toXML();
  11. }
  12. }
  13. }

代码示例来源:origin: zanata/zanata-platform

  1. @Test
  2. public void buildElementXMLStreamReader() throws Exception {
  3. XMLStreamReader reader = xif.createXMLStreamReader(is);
  4. while (reader.hasNext()) {
  5. int eventType = reader.next();
  6. if (eventType == START_ELEMENT
  7. && reader.getLocalName().equals("tu")) {
  8. ElementBuilder.buildElement(reader).toXML();
  9. }
  10. }
  11. }

代码示例来源:origin: zanata/zanata-platform

  1. /**
  2. * Supported children are currently {@code <prop>} and {@code <note>}.
  3. *
  4. * @param child
  5. * @param childrenXml
  6. */
  7. private static void addChildIfSupported(Element child,
  8. Builder<String> childrenXml) {
  9. String uri = child.getNamespaceURI();
  10. String name = child.getLocalName();
  11. if (inTmxNamespace(uri)
  12. && (name.equals("prop") || name.equals("note"))) {
  13. Element copy = (Element) child.copy();
  14. copy.setNamespacePrefix("");
  15. copy.setNamespaceURI("");
  16. childrenXml.add(copy.toXML());
  17. }
  18. }

代码示例来源:origin: zanata/zanata-platform

  1. /**
  2. * Sets all the TUV's metadata (attributes and children)
  3. *
  4. * @throws TMXParseException
  5. */
  6. public static void setMetadata(TransMemoryUnitVariant toTuv,
  7. Element fromTuvElem) throws TMXParseException {
  8. Map<String, Object> metadata = buildMetadata(fromTuvElem);
  9. String lang = (String) metadata.remove(XML_LANG);
  10. if (lang != null) {
  11. toTuv.setLanguage(getValidLang(lang));
  12. } else {
  13. throw new TMXParseException(
  14. "missing xml:lang in tuv: " + fromTuvElem.toXML());
  15. }
  16. setSharedMetadata(toTuv, metadata);
  17. }

代码示例来源:origin: concordion/concordion

  1. public void testAddsHeadIfMissing() throws Exception {
  2. improver.beforeParsing(document);
  3. assertEquals("<html><head /></html>", html.toXML());
  4. // Check it does not add it again if we repeat the call
  5. improver.beforeParsing(document);
  6. assertEquals("<html><head /></html>", html.toXML());
  7. }

代码示例来源:origin: zanata/zanata-platform

  1. @Test
  2. @Ignore
  3. public void buildElementXMLStreamReaderTransformer() throws Exception {
  4. // Nasty way to ensure that we get a Transformer which supports
  5. // StAXSource:
  6. System.setProperty("javax.xml.transform.TransformerFactory",
  7. "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
  8. Transformer t = TransformerFactory.newInstance().newTransformer();
  9. XMLStreamReader reader = xif.createXMLStreamReader(is);
  10. while (reader.hasNext()) {
  11. int eventType = reader.next();
  12. if (eventType == START_ELEMENT
  13. && reader.getLocalName().equals("tu")) {
  14. ElementBuilder.buildElement(reader, t).toXML();
  15. }
  16. }
  17. }
  18. }

代码示例来源:origin: concordion/concordion

  1. public void testAddsContentTypeMetadataIfMissing() throws Exception {
  2. metadataCreator.beforeParsing(document);
  3. assertEquals("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML());
  4. }

代码示例来源:origin: org.specrunner/specrunner-objects

  1. @Override
  2. public void processList(IContext context, Object instance, RowAdapter row, IResultSet result, List<Object> list) throws Exception {
  3. if (list.isEmpty()) {
  4. for (int i = 0; i < row.getCellsCount(); i++) {
  5. result.addResult(Success.INSTANCE, context.newBlock(row.getCell(i).getElement(), this));
  6. }
  7. } else {
  8. Exception e = new PluginException("Element found in object repository. XML:" + row.getElement().toXML());
  9. for (int i = 0; i < row.getCellsCount(); i++) {
  10. result.addResult(i == 0 ? Failure.INSTANCE : Warning.INSTANCE, context.newBlock(row.getCell(i).getElement(), this), i == 0 ? e : null);
  11. }
  12. }
  13. }
  14. }

代码示例来源:origin: concordion/concordion

  1. public String process(String html) {
  2. Element rootElement = new TestRig()
  3. .process(html)
  4. .getXOMDocument()
  5. .getRootElement();
  6. removeIrrelevantElements(rootElement);
  7. return rootElement.toXML();
  8. }

代码示例来源:origin: concordion/concordion

  1. public void testDoesNotAddContentTypeMetadataIfAlreadyPresent() throws Exception {
  2. Element meta = new Element("meta");
  3. meta.addAttribute(new Attribute("http-equiv", "Content-Type"));
  4. meta.addAttribute(new Attribute("content", "text/html; charset=UTF-8"));
  5. head.appendChild(new Element(meta));
  6. assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML());
  7. metadataCreator.beforeParsing(document);
  8. assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head></html>", html.toXML());
  9. }
  10. }

代码示例来源:origin: concordion/concordion

  1. public String process(String html) {
  2. Element rootElement = new TestRig()
  3. .process(html)
  4. .getXOMDocument()
  5. .getRootElement();
  6. removeIrrelevantElements(rootElement);
  7. return rootElement.toXML();
  8. }

代码示例来源:origin: concordion/concordion

  1. @Test // See Issue 26
  2. public void xmlOutputContainsAnExplicitEndTagForScriptElement() {
  3. JavaScriptLinker javaScriptLinker = new JavaScriptLinker(NOT_NEEDED_PARAMETER);
  4. Element html = new Element("html");
  5. Element head = new Element("head");
  6. html.appendChild(head);
  7. javaScriptLinker.beforeParsing(new Document(html));
  8. assertEquals("<head><script type=\"text/javascript\"></script></head>", head.toXML());
  9. }
  10. }

代码示例来源:origin: cdk/cdk

  1. public static IChemModel roundTripChemModel(Convertor convertor, IChemModel model) throws Exception {
  2. String cmlString = "<!-- failed -->";
  3. Element cmlDOM = convertor.cdkChemModelToCMLList(model);
  4. cmlString = cmlDOM.toXML();
  5. logger.debug("CML string: ", cmlString);
  6. CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));
  7. reader.close();
  8. IChemFile file = (IChemFile) reader.read(model.getBuilder().newInstance(IChemFile.class));
  9. Assert.assertNotNull(file);
  10. Assert.assertEquals(1, file.getChemSequenceCount());
  11. IChemSequence sequence = file.getChemSequence(0);
  12. Assert.assertNotNull(sequence);
  13. Assert.assertEquals(1, sequence.getChemModelCount());
  14. IChemModel chemModel = sequence.getChemModel(0);
  15. Assert.assertNotNull(chemModel);
  16. return chemModel;
  17. }

代码示例来源:origin: cdk/cdk

  1. public static IReaction roundTripReaction(Convertor convertor, IReaction reaction) throws Exception {
  2. String cmlString = "<!-- failed -->";
  3. Element cmlDOM = convertor.cdkReactionToCMLReaction(reaction);
  4. cmlString = cmlDOM.toXML();
  5. IReaction roundTrippedReaction = null;
  6. logger.debug("CML string: ", cmlString);
  7. CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));
  8. IChemFile file = (IChemFile) reader.read(new org.openscience.cdk.ChemFile());
  9. reader.close();
  10. Assert.assertNotNull(file);
  11. Assert.assertEquals(1, file.getChemSequenceCount());
  12. IChemSequence sequence = file.getChemSequence(0);
  13. Assert.assertNotNull(sequence);
  14. Assert.assertEquals(1, sequence.getChemModelCount());
  15. IChemModel chemModel = sequence.getChemModel(0);
  16. Assert.assertNotNull(chemModel);
  17. IReactionSet reactionSet = chemModel.getReactionSet();
  18. Assert.assertNotNull(reactionSet);
  19. Assert.assertEquals(1, reactionSet.getReactionCount());
  20. roundTrippedReaction = reactionSet.getReaction(0);
  21. Assert.assertNotNull(roundTrippedReaction);
  22. return roundTrippedReaction;
  23. }

代码示例来源:origin: concordion/concordion

  1. public void testTransfersEverythingBeforeBodyIntoNewlyCreatedHead() throws Exception {
  2. Element style1 = new Element("style1");
  3. Element style2 = new Element("style2");
  4. html.appendChild(style1);
  5. html.appendChild(style2);
  6. Element body = new Element("body");
  7. body.appendChild("some ");
  8. Element bold = new Element("b");
  9. bold.appendChild("bold text");
  10. body.appendChild(bold);
  11. html.appendChild(body);
  12. improver.beforeParsing(document);
  13. assertEquals("<html><head><style1 /><style2 /></head><body>some <b>bold text</b></body></html>", html.toXML());
  14. }

相关文章