【问题标题】:How to print the entire tag strcuture in a org.jdom.Document object?如何在 org.jdom.Document 对象中打印整个标签结构?
【发布时间】:2013-12-06 05:55:08
【问题描述】:

我是 Java 中 XML Parsing 的新手,我有以下问题:

如果在我的 Java 代码中有类似的内容:

org.jdom.Document documentXML = builder.build(new StringReader(myResponse));
System.out.println("documentXML:\n" + documentXML.toString());

当我去执行前面的命令时,我得到以下输出:

documentXML:
[Document:  No DOCTYPE declaration, Root is [Element: <s:Envelope [Namespace: http://schemas.xmlsoap.org/soap/envelope/]/>]]
objectElement: [Element: <s:Body [Namespace: http://schemas.xmlsoap.org/soap/envelope/]/>]

在我看来,我没有看到 Document 对象的全部内容。我该怎么做才能看到这个对象中的整个标签?

Tnx

安德烈亚

【问题讨论】:

  • 您最近的另一个问题表明您正在使用 JDOM 2.0.x .... 确保您只使用一个版本的 JDOM(用于 JDOM 2.x 和 org.jdom 的 org.jdom2.Document。 JDOM 1.x 的文档)

标签: java xml xpath xml-parsing jdom


【解决方案1】:

您是否尝试过使用 XMLOutputter 类。你可以这样做:

new XmlOutputter().output(document, System.out);

您还可以指定格式。如果你想要漂亮的打印:

 new XmlOutputter(Format.getPrettyFormat()).output(document, System.out);

文档可通过here获取。

【讨论】:

  • mmm 问题是我的对象 documentXML 的类型是 org.jdom.Document 而不是 Document,所以它出错并告诉我将此变量的类型更改为 Document...但我不知道 ot Document 和 org.jdom.Document 是一回事……我也试着做一个演员,但这是不可能的
  • I 方法实际上需要一个 org.jdom.Document。只需使用您的 documentXML 对象调用 output() 方法就可以了。
猜你喜欢
  • 2012-01-05
  • 1970-01-01
  • 2014-07-10
  • 2014-07-07
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
  • 2021-11-30
  • 1970-01-01
相关资源
最近更新 更多