Java SimpleXML从特定元素获取内部XML
我在从一个字段提取值时遇到问题。示例Java SimpleXML从特定元素获取内部XML,java,simple-framework,Java,Simple Framework,我在从一个字段提取值时遇到问题。示例XML如下: <Rule id="xccdf_org.cisecurity.benchmarks_rule_4.1.2_Ensure_that_the_kubelet_service_file_ownership_is_set_to_rootroot" selected="false" weight="1.000000" role="full"> <tit
XML
如下:
<Rule id="xccdf_org.cisecurity.benchmarks_rule_4.1.2_Ensure_that_the_kubelet_service_file_ownership_is_set_to_rootroot" selected="false" weight="1.000000" role="full">
<title
xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en">Ensure that the kubelet service file ownership is set to root:root
</title>
<description
xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en">
<xhtml:p>Ensure that the
<xhtml:span class="inline_block">kubelet</xhtml:span> service file ownership is set to
<xhtml:span class="inline_block">root:root</xhtml:span>.
</xhtml:p>
</description>
</Rule>
课程及类别:
@Root(strict = false, name = "Rule")
public class Rule {
@Element
String title;
@Element(required = false,type = RuleDescription.class)
RuleDescription description;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
@Root(strict = false, name = "description")
public class RuleDescription {
@Element(name = "p", required = false)
String description;
}
输出为:
-----------------------------------------------
Title: Ensure that the kubelet service file ownership is set to root:root, Desc: Ensure that the
-----------------------------------------------
这意味着SimpleXML
只需读取值,并在其路径上出现的第一个标记之前断开。我想得到描述的全部值,即:
确保kubelet服务文件所有权设置为root:root。
或者更好,如果没有像这样的标记,请确保kubelet服务文件所有权设置为root:root
,但我只需删除标记即可
有人能给我一个提示吗?尝试使用Simple Framework的Convert类。您可能需要编写自己的转换器类来解析上述XML
-----------------------------------------------
Title: Ensure that the kubelet service file ownership is set to root:root, Desc: Ensure that the
-----------------------------------------------