Skip to content

Tag: xpath

How to search in XML? (PHP)

I am working on a word application. I’m trying to get values from XML. My goal is getting the first and last letter of a word. Could you help me, please? PHP code: Answer The letter is in an attribute named ‘category’. Or in SimpleXML

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”. I tried it like that, but I dont get any result. What is the right way to extract the content with these both conditions and get the result: Answer Since this is a single element you should not

How to compare conetent with two tags using Xpath

I have below scenarios of $html contents. I want to check if html content is start with a media (image or video, iframe) without any text content like 3rd scenario. //no contetn between first p tag and image tag //no content between first p tag and video tag //having content inside first p tag I have tried like this but

Why using DOMDocument makes site load slower?

I’m using DOMDocument with xpath to load some data to my site from external (fast) website. Right now I use 4 urls (please see below). I need to increase to 8 urls. What I have noticed, that the more of those you add, the more slower the site loads. Is there any way to use xpath for more faster load?

PHP iterate every node of html string including text nodes splited by other nodes

I trying to change every readable part of given HTML code using DOMDocument and DOMXPath It gives me But strings “TEST_1” and “TEST_2” not changed, because of $xpath->evaluate(‘//[count() = 0]’) gives me only nodes without childrens. How to get all nodes with nodes like “TEST_1” and “TEST_2”? How to prevent adding <html> and <body> tags to result? Answer Unfortunately, I

PHP simpleXMLelment xpath returns unexpected results

I have executed the following code on the the sample XML at the bottom of the question and I am getting unexpected results. I would expect this to return only the two record nodes that are children of the current addresses node. But, it actually returns all 5 of the record nodes of the original $xml element. Everything I have