如何使用 Dom4j 测试元素的 CDATA 值?
有人知道如何找出元素是否包含 吗?我搜索了 dom4j API 和 Jaxen,但找不到如何执行此操作...如果我检索文本,则 cdata 包装器会被修剪。
Does anybody have an idea how to find out whether an element contains <![CDATA[ text ]]>
or not ? I search through the dom4j API and Jaxen and I can't find how to do that... If I retrieve the text, it the cdata wrapper is trimmed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://dom4j.sourceforge .net/dom4j-1.6.1/apidocs/org/dom4j/Node.html#getNodeType%28%29
这行得通吗?
根据节点类型返回代码。这使得多态处理节点变得更加容易,因为可以使用 switch 语句而不是多个 if (instanceof) 语句。
返回:节点类型(例如 ELEMENT_NODE 或 ATTRIBUTE_NODE)的 W3C DOM 兼容代码
http://dom4j.sourceforge.net/dom4j-1.6.1/apidocs/org/dom4j/Node.html#getNodeType%28%29
will this work?
Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.
Returns: a W3C DOM complient code for the node type such as ELEMENT_NODE or ATTRIBUTE_NODE
从技术上讲,你仍然可以这样做。
Technically you can still do this.
该方法:
返回整个元素,其值未经任何修改。
因此,如果您有:
调用文本方法将返回“value”,但调用“asXML()”将返回:
从那里,我想您可以对 CDATA 标记进行字符串搜索。
The method:
returns the entire element with its value unmodified by anything.
So if you have:
Calling the text methods will return "value", but calling "asXML()" will return:
From there, I guess you can do a String search for the CDATA tag.