Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设这是位置元素:<.location>blah...<./location>
它可以像这样为空:<.location/>
有没有办法检测空元素中的反斜杠以便不返回它?
如果您真正想要的是位置标记内的文本,您可以使用正确的 XPath 轻松找到它们:
doc.search('//location/text()')
如果出于某种原因,您实际上需要 location 元素本身,请使用:
doc.search('//location/text()/..')
<location/>在语义上与 相同<location></location>,因此应该这样对待。要查找所有空标签,只需跳过没有任何子节点(包括文本)的元素。
<location/>
<location></location>