gpt4 book ai didi

Java XMLStreamReader,当文本包含START_ELEMENT时如何获取元素文本

转载 作者:数据小太阳 更新时间:2023-10-29 02:08:49 25 4
gpt4 key购买 nike

如果我有一个 XML 元素,例如:

<title>this is a title</title>

使用 XMLStreamReader.getElementText() 很容易获取文本。但是,如果我遇到这样的元素,我无法弄清楚如何获取文本:

<title>this is a <othertag>title with another</othertag> tag inside of it</title>

我什至不确定那是否是有效的 XML,但它似乎通过了我试过的 W3C validator 。根据the API docs ,如果您要在其中遇到另一个 START_ELEMENT 事件,则不能使用 getElementText() 获取文本。那么...您可以使用什么?

最佳答案

使用getText

getText() returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved, any character data will be reported as CHARACTERS events.

关于Java XMLStreamReader,当文本包含START_ELEMENT时如何获取元素文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13218352/

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