Loop over DOMDocument

Try this: $doc = new DOMDocument(); $doc->loadHTML($html); showDOMNode($doc); function showDOMNode(DOMNode $domNode) { foreach ($domNode->childNodes as $node) { print $node->nodeName.’:’.$node->nodeValue; if($node->hasChildNodes()) { showDOMNode($node); } } }

PHP: using DOMDocument whenever I try to write UTF-8 it writes the hexadecimal notation of it

Ok, here you go: $dom = new DOMDocument(‘1.0’, ‘utf-8’); $dom->appendChild($dom->createElement(‘root’)); $dom->documentElement->appendChild(new DOMText(‘ירושלים’)); echo $dom->saveXml(); will work fine, because in this case, the document you constructed will retain the encoding specified as the second argument: <?xml version=”1.0″ encoding=”utf-8″?> <root>ירושלים</root> However, once you load XML into a Document that does not specify an encoding, you will lose … Read more

CakePHP Xml utility library triggers DOMDocument warning

This is a bug in PHPs DOMDocument::createElement() method. Here are two ways to avoid the problem. Create Text Nodes Create the textnode separately and append it to the element node. $dom = new DOMDocument; $dom ->appendChild($dom->createElement(‘element’)) ->appendChild($dom->createTextNode(‘S & T: ERROR’)); var_dump($dom->saveXml()); Output: string(58) “<?xml version=”1.0″?> <element>S &amp; T: ERROR</element> ” This is the originally intended … Read more

Convert clickable anchor tags to plain text in html document

You should be using DOM to parse HTML, not regular expressions… Edit: Updated code to do simple regex parsing on the href attribute value. Edit #2: Made the loop regressive so it can handle multiple replacements. $content=” <p><a href=”http://www.website.com”>This is a text link</a></p> <a href=”http://sitename.com/#foo”>bah</a> <a href=”#foo”>I wont change</a> “; $dom = new DOMDocument(); $dom->loadHTML($content); … Read more

Cannot use `document.execCommand(‘copy’);` from developer console

document.execCommand(‘copy’) must be triggered by the user. It’s not only from the console, it’s anywhere that’s not inside an event triggered by the user. See below, the click event will return true, but a call without event won’t and a call in a dispatched event also. console.log(‘no event’, document.execCommand(‘bold’)); document.getElementById(‘test’).addEventListener(‘click’, function(){ console.log(‘user click’, document.execCommand(‘copy’)); }); … Read more

XML parse VBA excel (function trip, & MSXML2.DOMDocument)

As close as possible to your OP I ‘d draw your attention to several errors or misunderstandings: [1] Invalid .LoadXML Syntax What is then the difference between .LoadXML (“C:\folder\folder\name.xml”) and .Load (“C:\folder\folder\name.xml”) ? Load expects a file path and then loads the file content into the oXML object. LoadXML doesn’t expect a file parameter, but … Read more