gpt4 book ai didi

java - 使用 Dom Java 对 XML 元素的文本内容进行标记

转载 作者:行者123 更新时间:2023-12-02 06:10:57 26 4
gpt4 key购买 nike

我有一个 XML 文件,其中包含以下标签:

<P>(b) <E T="03">Filing of financial reports.</E> (1)(i) Except as provided in paragraphs (b)(3) and (h) of this section,</p>

我需要解析文本内容并将结果作为字符串数组返回 ["(b)", "Filing of financial reports.", "(1)(i) Except as provided in paragraphs (b) (3) and (h) of this section,"]

换句话说,我需要对 <p> 的文本内容进行标记化元素根据<E T=03">并将结果存储在字符串数组中。

最佳答案

没有什么可以“标记化”的,因为在构建 DOM 时已经为您完成了解析。 <P>节点包含文本子节点。这就是 DOM 的样子:

P
|
+---text "(b) "
|
+---E
| |
| +---attribute T=03
| |
| +---text "Filing of financial reports."
|
+---text "Except as provided ..."

要获得所需的结果,您需要浏览 <P> 的子节点并提取所有文本节点。

关于java - 使用 Dom Java 对 XML 元素的文本内容进行标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21889920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com