domdocument

Getting content of the node having childs via DOMDocument

I have following html: <html ><body >Body text <div >div content</div></body></html> How could I get content of body without nested <div>? I need to get 'Body text', but do not have a clue how to do this. result of running $domhtml = DOMDocument::loadHTML($html); print $domhtml->getElementsByTagName('body')->item(0)->nodeValue; ...

Dump XML Posts from 'php://input' to file

I'm trying to write a parser for a xml postback listener, but can't seem to get it to dump the xml for a sample. The API support guy told me to use 'DOMDocument', maybe 'SimpleXML'? Anyways here's the code: (thanks!) <?php $xml_document = file_get_contents('php://input'); $doc = new DOMDocument(); $doc->loadXML($xml_document);...

Malformed XML when generating RSS with PHP DOMDocument

I am trying to generate a Google Merchant RSS Feed, using PHP's SimpleXML and DOMDocument. The actual generating code goes like that: $dom = new DOMDocument('1.0', 'utf-8'); $dom->formatOutput = true; $pRSS = $dom->createElement('rss'); $pRSS->setAttribute('version', '2.0'); $pRSS->setAttribute('xmlns:g', 'http://base.google.com/ns/1....

PHP DOmDocument , XML and CSS - can't get it to work

Hi there, I am generating an XML stream with a DomDocument. I need the pure XML stream, so I don't want to change the sourcecode with an xsl Transformation. Nevertheless I want people to be able to 'read' the XML in their browser without right click->View Source. So what I do is I create a DomDocument and add a processing instruction: ...

Making the nodes to ignore namespaces (prefixes) after changing XML structure. PHP DOMDocument

Hello. Original XML (myfile.xml) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <blabla xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:blabla="http://www.w3.org/2000/blabla" xmlns="http://www.w3.org/2000/b...

Fetching latest blog post on wordpress using php?

Hey, I have used this php to fetch my blog's latest post: function read_rss($display=0,$url='') { $doc = new DOMDocument(); $doc->load($url); $itemArr = array(); foreach ($doc->getElementsByTagName('item') as $node) { if ($display == 0) { break; } $itemRSS = array ( 'tit...

Using DOMDOcument in PHP to parse XML and return an array of tree structure

Hello there, I am very sorry if my question doesn't make sense as this is my first question, however i've been going through the questions posted for a while now. right i have a XML structure of <category> <id>123456</id> <name>Sales</name> <categories> <category> <id>2345</id> <name>UK House prices</name> </category> ...

PHP DOM: change doctype of existing DOMDocument

When creating a DOMDocument with DOMImplementation::createDocument(), you can specify a doctype as the third argument in the constructor. This doctype then gets "tied" to the document and you can retrieve it later with $document->doctype. However, this is a read-only attribute (unlike encoding and version!). Is there any way to change...

PHP DomDocument, DomXPath encoding issue

Hi, I'm having a problem with encoding from a wordpress feed that I just can't seem to figure out. I was loading my feed with DOMDocument->load but then did a file_get_contents and am now using ->XMLload with the same results. I did the XMLload so I could manipulate the feed if needed. The correct output that I'm looking for is - ‘ £....

Run a javascript file on a set of html documents

I have a set of html documents on local disk to process. I need to load each document file as document object and run a piece of javascript code over it and store the result in a separate file. I would prefer to this from python though I'm open to any other suggestions too. I tried to do this through extensions in chrome and firefox b...

php domdocument: when i create an xml, how can i ident each element properly?

Hiya. When i create an XML using php's DomDocument it creates the xml properly but all the elements are in one line, the xml file itself is not so readable. I searched in google and find that the attribute formatOutput in DomDocument should resolve the issue, i use php 5.3 and i do not have this properly in DomDocument. any ideas? ...

Character encoding error!

Hi! I try get the content this URL: http://www.chromeball.com, but the character encoding is not good. I have this code: $url = 'http://www.chromeball.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($ch); curl_close($ch); $dom = new DOMDocu...

PHP DOMElement getElementsByTagName specific selector

$content = file_get_contents(http://www.domain.com/page.html); $dom = new DOMDocument(); if (!@$dom->loadHTML($content)) die ("Couldn't load file?"); $title = $dom->getElementById("cssid"); $data['heading'] = $title->nodeValue; // this works fine I would like to be able to select all p tags that are within a certain id. With Jquery ...

Bulletproofing SimpleXMLElement

Everyone knows that we should always use DOM techniques instead of regexes to extract content from HTML, but I get the feeling that I can never trust the SimpleXML extension or similar ones. I'm coding a OpenID implementation right now, and I tried using SimpleXML to do the HTML discovery - but my very first test (with alixaxel.myopenid...

Why are warning messages generated about duplicate IDs when there are none?

Hi, all! The following is an unexpected warning message the server is giving me: Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: ID page3 already defined in Entity, line: 25 in C:\Program Files\Zend\Apache2\htdocs\joom\templates\valueTemplate\updateRecord.php on line 74 . . The above warning message is generated upon executi...

insert multiple data in xml with php dom

since i'm new to xml, i tried out the code over here, to insert data into xml, which works. But I would like to insert multiple data into xml. how would i achieve that? for example: <root> <no>1</no> <activity>swimming</activity> <date>29/7/2010</date> <others> <data1>data1</data1> <data2>data2</data2> <data3>data3</data3> s...

check if the file exists, if not, create

how do i check using php dom, if an xml file exists, and if not create it. <?php header("Location: index.php"); $xmldoc = new DOMDocument(); $xmldoc->load('sample.xml'); $newAct = $_POST['activity']; $root = $xmldoc->firstChild; $newElement = $xmldoc->createElement('activity'); $root->appendChild($newElemen...

aligning the xml document

i'm inserting the data into an xml file using php domdocument. however when i open the xml file, the data is displayed in a single line: <?xml version="1.0"?> <root><activity>swimming</activity><activity>jogging</activity></root> how do i align it programmatically like this? <?xml version="1.0"?> <root> <activity>swimming</activity...

if xml element exists, exit or skip

how do i check in xml [with php dom] that if a particular element exists, it should not repeat it. for example, if i have an element 'activity', it should check against the xml file if this element exists, and if it does, it will not create it again. in other words, i would like to create the element 'activity' only once in the beginnin...

using xsl displays nothing

i'm trying to implement an xsl file to an xml doc. however when i do so, it displays nothing. if i remove the reference of the xsl from the xml file, the data at least is displayed. this is the xsl code: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; <xsl:temp...