domdocument

Ignore the first XML tag in DOMDocument?

I write $xml = new DOMDocument(); and it automatically creates <?xml version="1.0"?>. I need to NOT create it. How do i do that? One solution is to search the first ">" and strsub at the index at the first < found. But i like a nicer way to do this. ...

DOMDocument parsing (php)

Hello, I am parsing an xml file from an API which I have converted into a DOMDocument in php. This is mostly fine but one problem I have is when I do this: $feeditem->getElementsByTagName('extra'); as part of a forall statment and the element extra doesn't exist in one of the feeditems I am iterating through in the forall condition th...

Php DOMDocument getting attibute of tag

Hello I have an api response in xml format with a series of items such as this: <item> <title>blah balh</title> <pubDate>Tue, 20 Oct 2009 </pubDate> <media:file date="today" data="example text string"/> </item> I want to use DOMDocument to get the attribute "data" from the tag "media:file". My attempt below doesn't work: $xmldoc = n...

php DomDocument, require first item only

Hello I have use DOMDocs in the past but I am stuck how to do this. $xmldoc = new DOMDocument(); $xmldoc->load('http://example.com'); $feeditem = $xmldoc->getElementsByTagName('data); I only want the first instance of the tag 'data'. Ordinarily I would write a foreach loop: foreach($feeditem as $element){ //} and do what i want wi...

PHP DomDocument Save XML with HTML

Hi, How would I save an XML file opened with DomDocument so that the HTML inside won't be encoded into HTML entities? ...

How do I create an XML file with php and have it prompt to download?

I'm using domdocument to create an xml file: $dom = new DOMDocument('1.0', 'iso-8859-1'); echo $dom->saveXML(); When I click the link to this file, it simply displays it as an xml file. How do I prompt to download instead? Furthermore, how can I prompt to download it as 'backup_11_7_09.xml' (insert todays date and put it as xml) inste...

PHP Command-line scripts are ignoring php.ini and ini_set('memory_limit',...) directives.

Hello, I am facing the common "Fatal error: Out of memory (allocated 30408704) (tried to allocate 24 bytes)..." PHP Fatal error. Pages served via Apache are not exhibiting this behavior. I've tried the following: Increasing the memory_limit in php.ini to a much larger value. Increasing memory_limit within the script itself via calls t...

DOMElement cloning and appending: 'Wrong Document Error'

There's something I don't fully understand about node cloning with the PHP's DOM api. Here's a sample file that quickly duplicates the issue I'm coming across. $doc = new DOMDocument( '1.0', 'UTF-8' ); $root = $doc->createElement( 'root' ); // This doesn't work either $root = new DOMElement( 'root' ); $doc->appendChild( $root ); $doc...

Possible to add HTML content to SimpleXMLElement node

Hey all, Simple question. Is it possible to add a block of HTML in a SimpleXMLElement (or as a matter of fact, DOMDocument) node without auto-converting the HTML data into entity format? For example, take this snippet (with DOMDocument here, but SimpleXMLElement behaves exactly the same): <?php $dom = new DOMDocument( '1.0', 'utf-...

Reddit RSS feed returning less items when requested through HTTP?

I am trying to read data from an RSS feed which has 25 items. When I request the RSS file through HTTP it says there are only 20 items. function test($location) { $doc = new DomDocument(); $doc->load($location); $items = $doc->getElementsByTagName('item'); return $items->length; } // Prints 20 echo test('http://www.red...

Why doesn't DOMXPath work?

I've been trying to write a PHP script to parse an XML document using DOMXPath; however it seems I'm missing something because none of my XPath queries are returning anything. So I've tried to water down my script to try and parse a very rudimentary XML document, and that's not working either. I've based this script off of this XPath exa...

How to un-nest nested lists in php

I have a nested unordered list like this (simplified version / the depth is variable) : <ul> <li> <a href="#">Root</a> <ul> <li> <a href="#">Page A</a> <ul> <li> <a href="#" title="Page A1">Page 1 2</a> </li> ...

How to get DOMDocument to be nice to ASCII control characters?

The HTML document which I am parsing contains some ASCII control codes. I noticed that PHP's DOMDocument parser truncates text nodes when it finds ASCII control characters within the node, such as Device Control 0x13 End of Medium 0x19 File Separator 0x1C Group Separator 0x1D Is this a bug or a feature? Is there any...

What is the Explanation for DOMDocument's Inconsistent Behavior when Dumping a non-ASCII Character?

I've noticed different "dumping" behaviors when using PHP's DOMDocument's saveXML() and saveHTML() methods. Here is a simple example of dumping the copyright symbol (). <?$domDoc = new DOMDocument(); $domDoc->loadHTML("&copy;"); echo $domDoc->saveHTML(); echo $domDoc->saveXML(); echo $domDoc->saveXML($domDoc); ?> The three du...

Error when merging two XML documents using XPath & DOMDocument ...

Hi, everyone. About a year ago I wrote a jQuery-inspired library which allowed you to manipulate the DOM using PHP's XPath and DOMDocument. I recently wanted to clean it up and post it as an open source project. I've been spending the past few days making improvements and implementing some more of PHP's native OO features. Anyhow, I th...

Format XML Document created with PHP - DomDocument

I am trying to format visually how my XML file looks when it is output. Right now if you go here and view the source you will see what the file looks like. The PHP I have that creates the file is: (Note, $links_array is an array of urls) header('Content-Type: text/xml'); $sitemap = new DOMDocument; // create r...

Sending a 'application/soap+xml' SOAP request using Classic ASP

Any help with this would be appreciated; I've been at it for a few days now. Below is the code that I've got so far; unfortunatly when I run it I get a HTTP 415 error; Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'. I have to send the content...

nodeValue from DomDocument returning weird characters in PHP

So I'm trying to parse HTML pages and looking for paragraphs (<p>) using get_elements_by_tag_name('p'); The problem is that when I use $element->nodeValue, it's returning weird characters. The document is loaded first into $html using curl then loading it into a DomDocument. I'm sure it has to do with charsets. Here's an example of a ...

PHP: Loading up an HTML file without it tidying my code

I am using the loadhtml function (http://php.net/manual/en/domdocument.loadhtml.phpt) to load up an external .html file. When I load it, it "tidy's" up my code, which, I don't want. I do NOT want a full HTML document, I only want html snippets in my .html, and I don't want the loadhtml file to try to make it valid html, because I don't...

PHP DOMDocument->loadXML with XML containing ampersand/less/greater ???

I'm trying to parse an XML string containing characters & < and > in the TEXTDATA. Normally, those characters should be htmlencoded, but in my case they aren't so I get the following messages: Warning: DOMDocument::loadXML() [function.loadXML]: error parsing attribute name in Entity ... Warning: DOMDocument::loadXML() [function.loadXML]...