Questions tagged [domdocument]

DOMDocument refers to a class encapsulating the DOM (Document Object Model). Various languages and technologies use the name DOMDocument for this purpose, for example PHP, COM, C++, and ActiveX

If you are thinking of using this tag, then you might be looking for the Document Object Model tag:

In PHP, for example, the DOMDocument class represents an entire HTML or XML document and serves as the root of the document tree.

2749 questions
133
votes
6 answers

PHP DOMDocument errors/warnings on html5-tags

I've been attempting to parse HTML5-code so I can set attributes/values within the code, but it seems DOMDocument(PHP5.3) doesn't support tags like
Klaas S.
  • 1,572
  • 2
  • 10
  • 11
132
votes
29 answers

How to saveHTML of DOMDocument without HTML wrapper?

I'm the function below, I'm struggling to output the DOMDocument without it appending the XML, HTML, body and p tag wrappers before the output of the content. The suggested fix: $postarray['post_content'] =…
Scott B
  • 38,833
  • 65
  • 160
  • 266
104
votes
8 answers

Detect Document Height Change

I'm trying to detect when my document height changes. Once it does, I need to run a few functions to help organize my page layout. I'm not looking for window.onresize. I need the entire document, which is larger than the window. How do I observe…
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
93
votes
4 answers

Disable warnings when loading non-well-formed HTML by DomDocument (PHP)

I need to parse some HTML files, however, they are not well-formed and PHP prints out warnings to. I want to avoid such debugging/warning behavior programatically. Please advise. Thank you! Code: // create a DOM document and load the HTML…
Viet
  • 17,944
  • 33
  • 103
  • 135
82
votes
8 answers

PHP XML how to output nice format

Here are the codes: $doc = new DomDocument('1.0'); // create root node $root = $doc->createElement('root'); $root = $doc->appendChild($root); $signed_values = array('a' => 'eee', 'b' => 'sd', 'c' => 'df'); // process one row at a time foreach…
Dakadaka
  • 1,453
  • 3
  • 15
  • 22
73
votes
5 answers

What's the difference between PHP's DOM and SimpleXML extensions?

I'm failing to comprehend why do we need 2 XML parsers in PHP. Can someone explain the difference between those two?
Stann
  • 13,518
  • 19
  • 65
  • 73
66
votes
5 answers

DOMDocument::loadHTML error

I build a script that combines all css on a page together to use it in my cms. It worked fine for a long time now i i get this error: Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag header invalid in Entity, line: 10 in css.php…
user1079160
  • 811
  • 1
  • 7
  • 11
61
votes
2 answers

XPath Query: get attribute href from a tag

I want to use XPath to get the href attribute from an a-tag, but it has two occurrences within the same file. How am I getting along? I need to check IF there is an href attribute with value $street/object, I have got this code and it does not…
user3239713
  • 781
  • 2
  • 6
  • 11
55
votes
3 answers

PHP DOMDocument failing to handle utf-8 characters (☆)

The webserver is serving responses with utf-8 encoding, all files are saved with utf-8 encoding, and everything I know of setting has been set to utf-8 encoding. Here's a quick program, to test if the output works:
Greg
  • 21,235
  • 17
  • 84
  • 107
52
votes
4 answers

What is anchorNode , baseNode , extentNode and focusNode in the object returned by document.getSelection?

If I make a selection in a html page and I do : var a = document.getSelection() I get an object with four properties : anchorNode baseNode extentNode focusNode the values of first three is the same i.e. the text that I have selected but how…
Rishul Matta
  • 3,383
  • 5
  • 23
  • 29
50
votes
3 answers

document.getelementbyId will return null if element is not defined?

In my code, I see this: if (document.getElementById('xx') !=null) { //do stuff } if xx element is not defined, will this evaluate to true or false? Should I write: if (document.getElementById('xx')) to be safe?
Victor
  • 16,609
  • 71
  • 229
  • 409
50
votes
5 answers

How to delete element with DOMDocument?

Is it possible to delete element from loaded DOM without creating a new one? For example something like this: $dom = new DOMDocument('1.0', 'utf-8'); $dom->loadHTML($html); foreach($dom->getElementsByTagName('a') as $href) if($href->nodeValue…
Kin
  • 4,466
  • 13
  • 54
  • 106
42
votes
2 answers

How to get html code of DOMElement node?

I have this html code: ...
SOMECONTENTWITHMORETAGS
I already can get the "foo" element (but only its content) with this…
Xaver
  • 11,144
  • 13
  • 56
  • 91
41
votes
2 answers

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' ); //…
Peter Bailey
  • 105,256
  • 31
  • 182
  • 206
37
votes
5 answers

How to insert HTML to PHP DOMNode?

Is there any way I can insert an HTML template to existing DOMNode without content being encoded? I have tried to do that with: $dom->createElement('div', '

Hello world

'); $dom->createTextNode('

Hello world

'); The output is pretty…
Nazariy
  • 6,028
  • 5
  • 37
  • 61
1
2 3
99 100