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

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

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

Element.toXML介绍

暂无

代码示例

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

public String toXML() {
  return xomElement.toXML();
}

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

public String toXML() {
  return xomElement.toXML();
}

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

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

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

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() );
  }
}

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

@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);
  }
}

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

@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();
    }
  }
}

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

@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();
    }
  }
}

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

/**
 * 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());
  }
}

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

/**
 * 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);
}

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

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

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

@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();
      }
    }
  }
}

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

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());
}

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

@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);
      }
    }
  }
}

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

public String process(String html) {
  Element rootElement = new TestRig()
    .process(html)
    .getXOMDocument()
    .getRootElement();
  removeIrrelevantElements(rootElement);
  return rootElement.toXML();
}

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

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());
  }
}

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

public String process(String html) {
  Element rootElement = new TestRig()
    .process(html)
    .getXOMDocument()
    .getRootElement();
  removeIrrelevantElements(rootElement);
  return rootElement.toXML();
}

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

@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());
  }
}

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

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;
}

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

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;
}

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

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());
}

相关文章