domdocument

Searching an HTML document in PHP

Hi there, I'm trying to use DOMDocument and XPath to search an HTML document using PHP. I want to search by a number such as '022222', and it should return the value of the corresponding h2 tag. Any thoughts on how this would be done? The HTML document can be found at http://pastie.org/1211369 ...

PHP: Fetch content from a html page using xpath()

I'm trying to fetch the content of a div in a html page using xpath and domdocument. This is the structure of the page: <div id="content"> <div class="div1"></div> <span class="span1></span> <p></p> <p></p> <p></p> <p></p> <p></p> <div class="div2"></div> </div> I want to get only the content of p, not spans and divs. I came thru this...

Display one XML entry based on id

Trying to make a quick and dirty news system. Have a basic XML file. <?xml version="1.0" encoding="ISO-8859-1"?> <articles> <article id="1"> <title>Article title 001</title> <short>Short text</short> <long>Long text</long> </article> <article id="2"> <title>Article title 002</title> <short>Short text</short> <lo...

Insert an xml element from an xml doc to an other xml document

Let's say I have to xml documents: <first_root> <element1/> <element2> <embedded_element/> </element2> </first_root> and <foo> <bar/> </foo> How can I put this second xml doc into the first one, using php and DomDocument or SimpleXML? I want it to look like something like this: <first_root> <element1/> <element2> ...

Access and manipulate XML file using DOMDocument

Hey all, I am trying to use DOMDocument to access an XML file, find data that matches a certain criteria, and then drop the node containing it if it does. I then need to create a new XML file with the remaining data. Below is the function I am using, with $current_balances being the full path to the XML file that i wish to use. I am ...

what is the purpose of DOMDocument->documentURI property ?

here is link to documentation: http://php.net/manual/en/class.domdocument.php#domdocument.props.documenturi But I do not understand is this setting a value that this object reveal, or is this setting that user can change ? Has this value any effect on html parsing by loadHTML metod ? Can it by used to absolutize all relative links in p...

XML not parsing correctly for no clear reason

Hi Guys, I have my XML feed being created from an associative array. Using new DOMDocument('1.0','UTF-8'); and it was working fine until I made some changes to the methods used to convert it from iso-8895-1 to UTF-8. The character being flagged up is the letter R, but I have gone into the file via ftp and changed it manually (deleted...

PHP DOMDucment and DOMXpath seem to be broken. Help Please (FIXED)

Hello All, So here is my problem in a nut shell. I'm working on a web scraping app for work and I've ran into a snag. I'm trying to load the HTML markup of a site using CURL, then use DOMDocument and XPath to find specific node values from that HTML. Initially, the user plugs in a URL which displays information they want to pull out o...

PHP DOMDocument validate against referenced XSI schema

Hello! I have a problem validating a given XML file in PHP. This works with a given $myFile xsi schema: function validate($file){ $xsi = $myFile; if(@!$this->dom->schemaValidate($xsi)){ $warning = error_get_last(); throw new Exception ('XML validation of file "'.$this->file.'" failed: '.$warning['message']); ...

How can I get a handle or object reference to an HtmlElement from a WebBrowser control HtmlDocument?

Think "Firebug", but entirely from C#. I have a WebBrowser control that I've built a DOM tree for in a TreeView. I'd like to be able to set a link between each DOM element in the TreeView and its matching HtmlElement in the WebBrowser's Document so that when the node in the tree is clicked, the matching element in the Document highlight...

Regex / DOMDocument - match and replace text not in a link

I need to find and replace text in a case insensitive way, unless it is within an anchor tag - for example: <p>Match this text and replace it</p> <p>Don't <a href="/">match this text</a></p> Searching for 'match this text' would only replace the first instance. [Edit] As per Gordon's comment, it may be preferred to use DOMDocument in...

xPath help > Find img with alt='My Keyword'

How can I alter this xpath to find if the content contains an img tag with an alt containing my keyword phrase? $xPath->evaluate('count(/html/body//'.$tag.'[contains(.,"'.$keyword.'")])'); ...

DOMDocument::validate() problem

Hello I have a big problem with the PHP DOMDocument::validate() who seems to ask the DTD systematically. It is a big problem when I whant to validate, for example, an XHTML document as explained here. As w3.org seems to reject all request from a PHP server, it's impossible to validate my document with this method... Is there any solu...