E
E
En1ken2017-10-09 22:24:42
PHP
En1ken, 2017-10-09 22:24:42

How to get list from xpath?

Hello everyone, there was such a problem. Need to get data from div block using xpath

<div class="reports">
  <div class="ERROR">
    <div class="name"></div>
    <div class="author"></div>
  </div>
  <div class="SUCCESS">
    <div class="name"></div>
    <div class="author"></div>
  </div>
  <div class="SUCCESS">
    <div class="name"></div>
    <div class="author"></div>
  </div>
  <div class="ERROR">
    <div class="name"></div>
    <div class="author"></div>
  </div>
  <div class="SUCCESS">
    <div class="name"></div>
    <div class="author"></div>
  </div>
</div>

The start of the query was
$xpath = new DOMXpath( $doc );
$results = $xpath->query( '//div[@class="reports"]' );
I understand that you need to use foreach, but how can I not understand and figure it out, while I need to get the value of the name attribute if it is in the div class="SUCCESS" block And the value of the author attribute if it is the div class="ERROR" block? Ready to thank you for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2017-10-09
@En1ken

Good afternoon.
You probably meant "get the values ​​inside a div with class = name".
You almost wrote the required xpath yourself. If in the forehead, then:
this is for name inside SUCCESS
this is for author inside ERROR

//div[@class="reports"]/div[@class="ERROR"]/div[@class="author"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question