Help us understand the problem. What is going on with this article?

XPathとCSSセレクター対応表

More than 5 years have passed since last update.

Yahoo PipesとかでXPathを使わなきゃいけないとき、CSSだとこう書くんだけどXPathでどう書いたらいいんだろう?と思って調べていたらとても良い対応表を書いている人がいたので翻訳してみた。

取得対象 CSS3 XPath
全ての要素 * //*
全てのP要素 p //p
全ての子要素 p > * //p/*
ID指定 #foo //*[@id='foo']
クラス指定 .foo //*[contains(@class,'foo')] ※
属性指定 *[title] //*[@title]
全てのPの最初の子要素 p > *:first-child //p/*[0]
子要素Aを持つ全てのP 不可 //p[a]
次の要素 p + * //p/following-sibling::*[0]

※この式はクラスが'foobar'でも'foo bar'でもマッチしてしまうので厳密には正しくありません。実際にこれらを区別しようと思ったらもっと複雑で複数の式を組み合わせる必要があるでしょう。

niusounds
iOSエンジニアLv1。AndroidはLv10くらい。
http://www.niusounds.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした