воскресенье, 11 июня 2017 г.

AQA. XPath - tools, examples

Tool for quick testing: link

Example 1:
Task: XML tree has:
proceedings
   -name
   -contents
      -article
         -description
         -title
         -pages
How can I identify any title that has only one description? And the number of articles that have more than three descriptions using xpath?

Decision:
Title with one description:
/proceedings/contents/article[count(description)=1]/title
Number of articles with more than three descriptions:
count(/proceedings/contents/article[count(description)>3])
 
Example 2:
Find element by span and text 
//span[text()='Мероприятия'] 
next element after f
 
Example 3: 
xpath select first element with attribute
(//*[@id="titleInput"])[1]
This will first get the book elements with the location attribute equal to 'US'. Then it will select the first node from that set. Note the use of parentheses, which are required by some implementations.
(note this is not the same as /bookstore/book[1][@location='US'] unless the first element also happens to have that location attribute )

Example 4:
Take element based on text inside (not by number of record)
<select name="garden">
    <option>Flowers</option>
    <option selected="selected">Shrubs</option>
    <option>Trees</option>
    <option selected="selected">Bushes</option>
    <option>Grass</option>
    <option>Dirt</option>
</select>
Xpath:
//*[@id="qualListContainer"]/option[.="HDTV"]
Xpath if number record used:
//*[@id="qualListContainer"]/option[3]

Example 5:
Button that contain link with text "Create"
//button[text()='Create']
the same variant:
//button[.='Create']
or by link text
//a[text()='text_i_want_to_find']/@href


Materials about it:
Stanford's free Introduction to Databases course

 

Комментариев нет:

Отправить комментарий

SEO: Эксперимент: как Яндекс и Google учитывают ключевые слова в URL

Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Дата пу...