- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 odt 文件(使用 LibreOffice 创建)读取数据。要求是获取绑定(bind)到文档中包含的 XForm 的 xml。我目前正在使用 odfdom-java 库来读取文件。到目前为止,我已经通过使用 jdom 解析文档来设法读取表单字段的值,但我真正想要的是获取包含表单数据的整个 xml。或者,我可以将文件加载为
OdfTextDocument.loadDocument("C://myFile.odt");
。
有谁知道如何从那里获取 XForm xml?
或者,如果我以编程方式将 odt 文件转换为 pdf 会有帮助吗?使用pdfbox我已经成功获得了acroform
PDDocument pdDoc = PDDocument.loadNonSeq( new File("C://myFile.odt"), null);
PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
PDAcroForm pdAcroForm = pdCatalog.getAcroForm();
但之后遇到同样的问题(如何获取带有表单数据的xml)。
最佳答案
我已经设法通过jdom(odfdom-java)做到这一点,毕竟没有使用。绑定(bind)的 xml 本身存在于表示 odt 的 xml 中。您所需要的只是知道表单的 id 或标签的名称,以便获得正确的节点。然后,构建一个包含带有表单数据的 xml 的字符串。我的代码如下:
import org.apache.xerces.dom.DeepNodeListImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class TestXFormData {
private static StringBuilder nodeContent;
public static void main(String[] args) throws Exception {
//Unzip the openOffice Document
ZipFile zipFile = new ZipFile("C://myFile.odt");
Enumeration entries = zipFile.entries();
ZipEntry entry;
while(entries.hasMoreElements()) {
entry = (ZipEntry) entries.nextElement();
if (entry.getName().equals("content.xml")) {
// construct document
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = domFactory.newDocumentBuilder();
Document doc = docBuilder.parse(zipFile.getInputStream(entry));
// print the document
printDocument(doc);
// get the node
NodeList list = doc.getElementsByTagName("myTagName");
Node node = ((DeepNodeListImpl) list).item(0);
nodeContent = new StringBuilder();
// print the xml with the form data
prettyPrint(node);
System.out.println(nodeContent.toString());
}
}
}
private static void prettyPrint(Node node) {
if (node.getNodeType() == Node.TEXT_NODE) {
nodeContent.append(node.getNodeValue());
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
nodeContent.append("<" + node.getNodeName() + ">");
NodeList kids = node.getChildNodes();
for (int i = 0; i < kids.getLength(); i++) {
prettyPrint(kids.item(i));
}
nodeContent.append("</" + node.getNodeName() + ">");
}
}
private static void printDocument(Document doc) throws IOException {
OutputFormat format = new OutputFormat(doc);
format.setIndenting(true);
XMLSerializer serializer = new XMLSerializer(System.out, format);
serializer.serialize(doc);
}
}
关于java - 使用java从odt文件读取XForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245500/
我正在寻找仅用于 ODT 文件的 HTML 表单上传。我需要知道 accept 的参数。 Upload 最佳答案 通过在 stackoverflow 中搜索,我发现我必须
有些格式实际上是伪装的 zip 文件,例如docx 或 odt。如果我将它们直接存储在版本控制中,它们将作为二进制文件处理。我理想的解决方案是 有一个创建 foo.docx/ 的钩子(Hook)每个
是否有可用的 C/C++ 库可用于创建、加载和保存 .odt 格式的文件? 或者,我在哪里可以找到有关实现 .odt(/ODF) 规范的类似教程的信息? 最佳答案 本站:OASIS OpenDocum
现在,我正在处理一个从其文件夹中消失的 odt 文件(不要问我为什么)。 ~$ df Filesystem 1K-blocks Used Available Use% Mounted
我认为使用 Emacs 和 org-mode 导出的 .odt 文档中的边距太大。 我该如何更改它们? org-mode 是否为此提供了特殊的 #+OPTION? 谢谢。 最佳答案 根据relevan
我认为使用 Emacs 和 org-mode 导出的 .odt 文档中的边距太大。 我该如何更改它们? org-mode 是否为此提供了特殊的 #+OPTION? 谢谢。 最佳答案 根据relevan
在我的 Java 应用程序中,我必须从 .odt 文档中读取数据。有人可以告诉我如何获取对此类文档中第一个表的引用吗?我想使用 Apache odf 工具包,但在那里我只找到了一种通过名称获取表的方法
我正在寻找一个能够从 odt 文件中提取文本的小型 linux 工具。 它只需要人类可读,并且它可能会遇到复杂对象等问题。 它几乎是 this question 的副本但我需要它很小并且不依赖于 Op
如何合并两个 .odt 文件?手动执行此操作,打开每个文件并复制内容是可行的,但不可行。 我已尝试使用 odttoolkit Simple API (simple-odf-0.8.1-incubati
我需要从 C# 中的 odf 文件(开放文档格式)中获取所有文本。我找到了 AODL 库,并安装了它。我访问了 AODL 的页面 https://wiki.openoffice.org找到关于如何完成
我正在使用Delphi打开MS Word .doc文档,并将其另存为文本文件。我现在需要做的是将其另存为.odt文件。 我找不到应该使用的过滤器属性。 这是“保存到文本文件”功能的代码片段: wP
我正在尝试将单段 HTML 代码转换为 *.odt 格式(Open Office)正在使用的 XML 格式。例如,This is some text应翻译为This is some text 。当然,
我们刚刚发现 whitepaper “观察驱动测试:是的,代码正在做你想做的事。顺便说一下,它还做了什么?”,并且很感兴趣。 但是,谷歌似乎并没有透露太多关于它在实践中是如何工作的(1,2)。那里的一
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 2 年前。 Improve t
我正在使用 C++ 和 Qt 编写富文本编辑器。现在,我希望它(至少)支持 .odt 格式。 我发现 QTextDocumentWriter 用于将 QTextDocument 的内容写入文件,但我似
我正在使用 Qt 4.5.3 和 Windows XP。我需要我的应用程序生成包含正在使用和生成的信息的文档。正在使用的信息将只是字符串(QString 更具体),正在生成的信息也将是字符串和图像。
我正在将数百个 ODT 文件转换为 PDF 文件,一个接一个地进行需要很长时间。我有一个多核 CPU。是否可以使用 bash 或 python 编写脚本来并行执行这些操作?有没有一种方法可以从命令行使
我使用 svn 来存储我的规范文件的修订,这些文件是用 oowrite (OpenOffice.org) 编写的。 我找不到比较 odt 文件的不同版本的方法。它提示它们是二进制的。 是否有任何工具或
我试过了odfWeave有点,不错的应用程序。但是一开始,即使我完全按照手册中提供的示例进行尝试,也无法生成任何文件。 我在 odt 文件中搜索了一下,在 content.xml 中找到了一条语句导致
最好使用 ODFDOM API。如果可能的话,我希望将整个文件的内容放在一个字符串中。如果没有,您将如何在文件中搜索特定子字符串? 提前致谢。 最佳答案 您将需要加载 odt 文档,然后获取内容根目录
我是一名优秀的程序员,十分优秀!