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

XPath : Contains() on a xml to find urls, but it actually find more

I’m trying to find the correct XPath expression to get only urls from all my documents, whatever the tag is. I’m trying with this one :

<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://url
    </loc>
    <lastmod>2019-08-07T15:01:51+00:00
    </lastmod>
  </url>
</urlset>

The following expression gives me these results :

//*[contains(.,’http’)]//text()

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

https://url

2019-08-07T15:01:51+00:00

What I’m looking for is to get rid of the second line. I need to be able to get only urls from any xml file.

>Solution :

Well, let’s ignore the fact that not all URLs contain "http" and not everything that contains "http" is a URL…

To find all text nodes containing "http", just use //text()[contains(., 'http')].

Or you could find

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