de.pdark.decentxml.Document类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(191)

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

Document介绍

[英]This class represents an XML document.

If you add a ProcessingInstruction as the first node of the document, it will be converted into an XMLDeclaration.

Note: The automatic creation of XMLDeclaration is not perfect; if you manipulate the list of nodes yourself (for example, via getNodes().add()), then you're on your own.
[中]此类表示XML文档。
如果将ProcessingInstruction添加为文档的第一个节点,它将转换为XMLDeclaration。
注意:XMLDeclaration的自动创建并不完善;如果您自己操作节点列表(例如,通过getNodes()。add()),那么就只能靠自己了。

代码示例

代码示例来源:origin: org.eclipse.tycho/tycho-metadata-model

public Feature(Document document) {
  this.document = document;
  this.dom = document.getRootElement();
}

代码示例来源:origin: org.eclipse.tycho/tycho-p2-facade

public static void write(TargetDefinitionFile target, File file) throws IOException {
  OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
  Document document = target.document;
  try {
    String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
    Writer w = new OutputStreamWriter(os, enc);
    XMLWriter xw = new XMLWriter(w);
    try {
      document.toXML(xw);
    } finally {
      xw.flush();
    }
  } finally {
    IOUtil.close(os);
  }
}

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

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
Cell cell = table.getFirstRow().getFirstCell();
builder.moveTo(cell.getFirstParagraph());

FieldBuilder fbuilder = new FieldBuilder(FieldType.FIELD_FORMULA);
fbuilder.addArgument("20000").addSwitch("\\# \"#,##0\"").buildAndInsert(builder.getCurrentParagraph());

doc.updateFields();
doc.save(MyDir + "Out.docx");

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

//Load the document
Document doc = new Document(MyDir + "in.docx");

//Get the first table in the document
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

//Get the first cell of first row
Cell cell = (Cell)table.getRows().get(0).getCells().get(0);

//Change the color of text
for (Run run : (Iterable<Run>)cell.getChildNodes(NodeType.RUN, true))
{
  run.getFont().setColor(Color.BLUE);
}

//Save the document
doc.save(MyDir + "Out.docx");

代码示例来源:origin: io.takari.nexus/nexus-perf

/**
 * Deploys provided pom.xml file under specified groupId, artifactId and version. The contents of the pom is updated
 * to match specified groupId, artifactId and version.
 */
public long deployPom(String groupId, String artifactId, String version, File pomTemplate) throws IOException {
 final Document pom = XMLParser.parse(pomTemplate);
 pom.getRootElement().getChild("groupId").setText(groupId);
 pom.getRootElement().getChild("artifactId").setText(artifactId);
 pom.getRootElement().getChild("version").setText(version);
 // pom.getRootElement().getChild( "packaging" ).setText( "pom" );
 StringWriter buf = new StringWriter();
 XMLWriter writer = new XMLWriter(buf);
 pom.toXML(writer);
 String body = buf.toString();
 HttpEntity pomEntity = new StringEntity(body, ContentType.TEXT_XML);
 deploy(pomEntity, groupId, artifactId, version, ".pom");
 return body.getBytes(Charsets.UTF_8).length;
}

代码示例来源:origin: io.provis/provisio-jenkins

public String finish() {
 return base.toXML();
}

代码示例来源:origin: de.pdark/decentxml

Document doc = new Document ();
    doc.addNode (docType);
  doc.addNode (n);
if (doc.getRootElement () == null)
  throw new XMLParseException ("No root element found");

代码示例来源:origin: io.provis/provisio-jenkins

private boolean mergeDoc(Document from, Document to) {
 Element rootFrom = from.getRootElement();
 String appendPath = rootFrom.getAttributeValue("appendPath");
 if (appendPath != null) {
  return appendPath(rootFrom, to, appendPath);
 }
 String replacePath = rootFrom.getAttributeValue("replacePath");
 if (replacePath != null) {
  return replacePath(rootFrom, to, replacePath);
 }
 Element rootTo;
 String mergePath = rootFrom.getAttributeValue("mergePath");
 if (mergePath != null) {
  Element child = to.getChild(mergePath);
  if (child == null) {
   throw new IllegalStateException("Cannot merge " + name + " to path " + mergePath);
  }
  rootTo = child;
 } else if (rootFrom.getName().equals(to.getRootElement().getName())) {
  rootTo = to.getRootElement();
 } else {
  return false;
 }
 merge(rootFrom, rootTo);
 return true;
}

代码示例来源:origin: de.pdark/decentxml

public Element getChild (String path, Namespace ns)
  if (getRootElement () == null)
    return null;
    if (path.equals (getRootElement ().getName ())
      && (ns == null || ns.equals (getRootElement ().getNamespace ()))
      return getRootElement ();
    else
      return null;
    ns2 = getNamespaces ().getNamespace (prefix);
    if (ns2 == null)
      throw new XMLParseException ("Namespace prefix '"+prefix+"' is not defined");
  if (!name.equals (getRootElement ().getName ())
    || (ns2 != null && !ns2.equals (getRootElement ().getNamespace ()))
  return getRootElement ().getChild (path.substring (pos+1), ns);

代码示例来源:origin: io.fabric8.forge/camel-tooling-util

protected Document createExemplarDoc() throws IOException {
  String exemplar = "io/fabric8/camel/tooling/exemplar.xml";
  URL url = findResource(exemplar, null);
  if (url != null) {
    return parse(new XMLIOSource(url));
  } else {
    LOG.warn("Could not find file {} on the class path", exemplar);
    Document d = new Document();
    d.addNode(new Element("beans", springNamespace));
    return d;
  }
}

代码示例来源:origin: de.pdark/decentxml

public Element getChild (String path)
{
  return getChild (path, null);
}

代码示例来源:origin: de.pdark/decentxml

return doc == null ? null : doc.getChild (path, ns);
  ns2 = getDocument ().getNamespace (prefix);
  if (ns2 == null)
    throw new XMLParseException ("Namespace prefix '"+prefix+"' is not defined");

代码示例来源:origin: de.pdark/decentxml

public Document createClone ()
{
  return new Document ();
}

代码示例来源:origin: de.pdark/decentxml

protected XMLDeclaration createXMLDeclaration ()
{
  if (xmlDeclaration == null)
  {
    addNode (0, new XMLDeclaration ("1.0"));
    addNode (1, new Text ("\n"));
  }
  return xmlDeclaration;
}

代码示例来源:origin: io.provis/provisio-jenkins

public void finish(Writer w) throws IOException {
 base.toXML(new XMLWriter(w));
 w.flush();
}

代码示例来源:origin: jboss-fuse/fabric8

protected Document createExemplarDoc() throws IOException {
  String exemplar = "io/fabric8/camel/tooling/exemplar.xml";
  URL url = findResource(exemplar, null);
  if (url != null) {
    return parse(new XMLIOSource(url));
  } else {
    LOG.warn("Could not find file {} on the class path", exemplar);
    Document d = new Document();
    d.addNode(new Element("beans", springNamespace));
    return d;
  }
}

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

Document doc = new Document(MyDir + "document.docx");
 // Retrieve the first table in the document.
 Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
 // Clone the last row in the table.
 Row clonedRow = (Row)table.getLastRow().deepClone(true);
 // Remove all content from the cloned row's cells. This makes the row ready for
 // new content to be inserted into.
 for (Cell cell: clonedRow.getCells())
{    
    cell.getFirstParagraph().getRuns().clear();
    cell.getFirstParagraph().appendChild(new Run(doc,"hello text"));
}
// Add the row to the end of the table.
table.appendChild(clonedRow);

doc.save(MyDir + "Table.AddCloneRowToTable Out.doc");

代码示例来源:origin: eclipse/tycho

public static IU read(File file) throws IOException {
  FileInputStream is = new FileInputStream(file);
  try {
    Document iuDocument = parser.parse(new XMLIOSource(is));
    Element root = iuDocument.getChild(UNIT);
    if (root == null)
      throw new RuntimeException("No iu found.");
    IU result = new IU(iuDocument, root);
    if (result.getId() == null)
      throw new RuntimeException(
          String.format("The IU defined in %s is missing an id.", file.getAbsolutePath()));
    if (result.getVersion() == null)
      throw new RuntimeException(
          String.format("The IU defined in %s is missing a version.", file.getAbsolutePath()));
    return result;
  } finally {
    IOUtil.close(is);
  }
}

代码示例来源:origin: org.sonatype.tycho/tycho-metadata-model

public Feature( Document document )
{
  this.document = document;
  this.dom = document.getRootElement();
}

代码示例来源:origin: org.eclipse.tycho/tycho-metadata-model

public static void write(ProductConfiguration product, File file) throws IOException {
  OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
  Document document = product.document;
  try {
    String enc = document.getEncoding() != null ? document.getEncoding() : "UTF-8";
    Writer w = new OutputStreamWriter(os, enc);
    XMLWriter xw = new XMLWriter(w);
    try {
      document.toXML(xw);
    } finally {
      xw.flush();
    }
  } finally {
    IOUtil.close(os);
  }
}

相关文章