问题标签 [jdom-2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
161 浏览

java - 如何通过右键单击从多个jtree中删除选定的jtree

在我的 GUI 中,我必须根据 JTree 结构一个一个地加载几个 XML 文件,如果我想通过右键单击来编辑或删除完整的 JTree 或值,我怎样才能有效地做到这一点?任何线索?

我将 xml 文件处理到 jtree,如下所示,

++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++

0 投票
1 回答
4439 浏览

java - 名称“”对于 JDOM/XML 命名空间是不合法的

我使用 JDOM2 从远程提要检索不受我控制的 XML。对于其中一个,我得到了这个错误:

名称 "" 对于 JDOM/XML 命名空间是不合法的:命名空间 URI 必须是非空且非空的字符串。

这是 XML 的示例:

如果我使用正则表达式删除 xsi:schemaLocation,该错误就会消失。

这是我的 JDOM2 解析代码。它在 builder.build 上失败

0 投票
1 回答
1913 浏览

java - 如何在 JDOM2 中获取 CDATA 的值

我正在尝试使用 getText() 在 JDOM2 中检索 CDATA 值,但我只得到以下内容 -
<![CDATA[ ]]>

我的 XML 如下所示

CDATA 包含我需要的 XML 内容作为字符串来存储它 elsewejhere 代码(片段)如下所示

getValue()工作正常,而getText()只返回<![CDATA[ ]]>

当然我的 XPAHT 看起来像这样 //ROOT/CHILD/P 知道如何获取 CDATA 的内容吗?

编辑:如果我重新 <P><![CDATA[ SOMECONTENT]]></P>获得“SOMECONTENT”..所以我无法从 CDATA 获取 XML 内容

0 投票
1 回答
1240 浏览

java - 如何使用 JDOM 将 JTree 数据导出为 XML 文件

我有一个 jtree,需要将每个子级元素另存为 xml,我尝试使用下面的代码来实现它,但是它在转换 xml 文档的数字数据时出错,

错误信息 :

错误指出,Element el = new Element(node.toString());

错误的原因可能是什么?

0 投票
1 回答
796 浏览

java - How to get JDOM2 Element text as a list if its content separated by its inner Elements?

I want to build up a String from an XML-file in Java, using JDOM2. The XML-file snippet what I want to process looks like the following:

The element 'title' contains useful textual content for me separated into several parts with inner Elements, and if any of the profiles turn active I have to insert the content of the inner Element amongst the right parts (only one can be active at a time but in this case it's not important).

Is there any elegant way to get the Element text back as an array of Strings for further operations?

Or if I get this on a wrong way how could I do it properly?

(Currently suffering with Element's 'getText' and 'getContent' methods, and the basics of 'XMLOutputter')

Thanks for any help!

0 投票
1 回答
122 浏览

dom - 如何在不考虑使用 JDom2 的空文本节点的情况下评估 xpath

对于 xml 段:

当我评估 xpath: //text()[preceding::text()[normalize-space(.)!=''][position()=1][normalize-space()='Price:']]时,结果是:

但我只想找到[$11.85]. 那么在不考虑空文本节点的情况下,我能做些什么来评估 xpath?

0 投票
1 回答
7126 浏览

java - No DOCTYPE declaration error in JDOM

My code is below

The purpose of this function is to convert data from object to XML and return the XML Document. To verify this "Document" I am saving the generated XML to a file c:\temp\OutputFile.xml & I get the XML as I need

But when i try to return the Document which is xIssuesMappingXMLInternal I always get the following Document: No DOCTYPE declaration, Root is element <ISSUES/>

Why is this c

The XML looks like below

Here I will have multiple nodes

My expectation is that the Document would return the whole ISSUES node.

Also I don't want to use any "doctype" here. it's a simple XML

I am using Java SE 1.6 with JDOM 2.0.4

Any help would be really appreciated

Many thanks

0 投票
2 回答
200 浏览

java - 当我在 xml 文件中写入信息时,Eclipse 显示错误

我使用 JDOM 库。当我将信息写入 xml 文件时,Eclipse 显示错误。该系统找不到指定的路径。我尝试在“语言”文件夹中创建文件。当我将信息写入此文件时,如何自动创建文件夹?我认为错误在这一行:

这是我的代码:

这是错误:

0 投票
2 回答
6217 浏览

java - Java jdom xml解析

这是我使用 java 的第一天,我尝试为我的网站构建一个小的 xml 解析器,这样我就可以在我的 sitemaps.xml 上有一个干净的外观。我使用的代码是这样的

当代码通过

我得到了 xml 站点地图的清晰打印。到那个时刻:

输出:

它还找到根元素。但是由于某种原因,当脚本应该用于孩子时,它会返回一个空打印:

输出:

我应该以其他方式做什么?有什么办法可以带孩子吗?

XML 看起来像这样

0 投票
1 回答
574 浏览

xpath-2.0 - 如何通过 Java 7 中的 XPath 使用 JDOM 2 获取所有元素名称?

我有一个如下所示的 XML 文件。

我想获取 Groups 子元素的所有名称(在本例中为“Default”和“GroupA”)作为字符串列表。我正在尝试以下。

除了以下例外,这很难失败。

什么是正确的语法?我不明白这个例外。