Questions tagged [domxpath]

domxpath is a class in PHP's DOM API to support XPATH 1.0

domxpath called the DOMXPath is a class in PHP's DOM API that support XPATH 1.0. It provides functions to run XPATH queries on the document and retrieve specific parts of the document

492 questions
28
votes
3 answers

PHP xpath contains class and does not contain class

The title sums it up. I'm trying to query an HTML file for all div tags that contain the class result and does not contain the class grid.
skip this div
grab this one
Thanks!
Rob
  • 631
  • 1
  • 7
  • 20
21
votes
3 answers

DOMXpath - Get href attribute and text value of an a element

So I have a HTML string like this: Some Name Some Name2 Using XPath I'm able to get value of href attribute using this Xpath…
Marko Jovanović
  • 2,647
  • 3
  • 27
  • 36
12
votes
4 answers

Traversing child nodes with PHP DOMXpath?

I'm having some trouble understanding what exactly is stored in childNodes. Ideally I'd like to do another xquery on each of the child nodes, but can't seem to get it straight. Here's my scenario: Data:

Bryan
  • 1,771
  • 4
  • 17
  • 30

12
votes
2 answers

What is the difference between DOMXPath::evaluate and DOMXPath::query?

Trying to decide which is more appropriate for my use case... After comparing the documentation for these methods, my vague understanding is evaluate returns a typed result but query doesn't. Furthermore, the query example includes looping through…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
7
votes
2 answers

DOMDocument / Xpath leaking memory during long command line process - any way to deconstruct this class

I've building a command line php scraping app that uses XPath to analyze the HTML - the problem is every time a new DOMXPath class instance gets loaded in a loop I'm getting a memory loss roughly equal to the size of the XML being loaded. The script…
Corelloman
  • 71
  • 2
6
votes
4 answers

PHP xpath query on XML with default namespace binding

I have one solution to the subject problem, but it’s a hack and I’m wondering if there’s a better way to do this. Below is a sample XML file and a PHP CLI script that executes an xpath query given as an argument. For this test case, the command line…
danorton
  • 11,804
  • 7
  • 44
  • 52
6
votes
5 answers

unable to scrape content from a website

I am trying to scrap some content from a website but the code below is not working(not showing any output). here is the code $url="some url"; $otherHeaders=""; //here i am using some other headers like content-type,userAgent,etc some curl to get…
lovesh
  • 5,235
  • 9
  • 62
  • 93
6
votes
1 answer

DOMXpath | Select the innermost divs

Im looking for a way to select the innermost div with PHP for example:
-
-
RobertPitt
  • 56,863
  • 21
  • 114
  • 161
6
votes
2 answers

XPath to get one level of childnodes

Using DOMXPath::query is it possible to get just one level deep of childNodes? For example if I had a document like:
I would…
Greg
  • 91
  • 1
  • 3
  • 5
6
votes
1 answer

How to select multiple attributes for XPath query

Possible Duplicate: How do I select multiple sets of attributes within an XML document using XPath? My HTML code: i want to select this table by specifying not only the width but also with…
Vainglory07
  • 5,073
  • 10
  • 43
  • 77
5
votes
2 answers

How can I remove
if no text comes before or after it? DOMxpath or regex?

How can I remove
if no text comes before or after it? For instance,


hello

hello

they should be rewritten like this,

hello

hello

Should I use DOMxpath or regex would be better? (Note: I have a post about…
Run
  • 54,938
  • 169
  • 450
  • 748
5
votes
2 answers

PHP's DOMXPath is stripping out my tags inside the matched text

I asked this question yesterday, and at the time it was just what I needed, but while working with some live data I discovered that is wasn't quite doing what I expected. Parse HTML with PHP's HTML DOMDocument It gets the data from the HTML page,…
Mint
  • 14,388
  • 30
  • 76
  • 108
5
votes
2 answers

Is registerNamespace necessary in PHP's DOMXPath?

I'm working with an XML like this: (it's a standard container.xml in an epub book)
cambraca
  • 27,014
  • 16
  • 68
  • 99
4
votes
2 answers

PHP XPath. How to return string with html tags?

Message bold, strike
Link, BOLD
Kirill Firsov
  • 509
  • 1
  • 7
  • 16
4
votes
2 answers

PHP DOMXPath Get Value with Full Path - No ID

I am trying to get a value of an element through a direct XPath as the element has no ID. $dom = new DOMDocument(); @$dom->loadHTML($rawHTML); $finder = new DOMXPath($dom); //this works well $elements =…
nomaam
  • 1,213
  • 2
  • 22
  • 37
1
2 3
32 33