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.
ノード内のアトミック値のみを選択したい。たとえば、次の「here」テキスト:
<a href="">here</a>
JavaでXpathを使用すると、次のようなオブジェクト/配列が返されます
[DomNode[<a href="">here</a>]]
欲しいのはテキストだけです。
これは可能ですか?ありがとう!
text()ノードテストを使用できます。たとえば、href 属性を持つすべてのアンカーのテキストを選択する場合は、次の XPath クエリを実行できます。
text()
//*/a/@href/../text()
使用:
//a[@href='']/text()
これにより、空の属性aを持つ、ドキュメント内の任意の要素の子であるすべてのテキストノードが選択されます。href
a
href