Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract content with Xpath and data attribute

I need to extract the content of the following div tag which has the data-visible="1" attribute and contains the div id "line".

<div class="line-name" id="line-10" data-visible="1">Need to extract</div>

I tried it like that, but I dont get any result.

$xpath->query('//*[contains(@id, "line")]//div[contains(@visible, "1")]');

What is the right way to extract the content with these both conditions and get the result:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Need to extract

>Solution :

Since this is a single element you should not use // after //*[contains(@id, "line")]. Also it is a data-visible attribute there, not visible.
You can use XPath expression like this:

'//div[contains(@id, "line") and @data-visible="1"]'

Or

'//div[contains(@id, "line")][@data-visible="1"]'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading