Category : domdocument

im trying to generate a sitemap.xml , here is simplified version of my code $dom = new DOMDocument(); $dom->encoding = ‘utf-8’; $dom->xmlVersion = ‘1.0’; $dom->formatOutput = true; $xml_file_name = ‘./sitemap.xml’; $urlset = $dom->createElement(‘urlset’); $attr_ = new DOMAttr(‘xmlns:xsi’, "http://www.w3.org/2001/XMLSchema-instance"); $urlset->setAttributeNode($attr_); $url_node = $dom->createElement(‘url’); $url_node_loc = $dom->createElement(‘loc’, ‘http://localhost’ ); $url_node->appendChild($url_node_loc); $url_node_lastmod = $dom->createElement(‘lastmod’, ‘2021-08-03T22:17:47+04:30’ ); $url_node->appendChild($url_node_lastmod); $urlset->appendChild($url_node); ..

Read more

I’m trying to remove span tags with a specific style (preserving the text) but don’t understand why the result is putting span text inside the first span in this example? $curr_notes = ‘<span style="color: rgb(226, 80, 65);"><br></span><span style="color: rgb(0, 0, 0);">TEXT 1</span><br><span style="color: rgb(0, 0, 0);">TEXT2</span>’; $pattern = ‘//span[@style="color: rgb(0, 0, 0);"]’; $dom = new ..

Read more

I have an XPath like this. I am trying to do exact match a string in the HTML. $d->loadHTML(‘<?xml encoding="UTF-8">’.$html); $xpath = new DOMXPath($d); $txt="rest"; $txt=’ ‘.$txt.’ ‘; $txt1=strtolower($txt); $xpath->query(‘/html/body//text()[‘. ‘contains(‘. ‘translate(.,"’.strtoupper($txt).’","’.$txt1.’"),’. ‘"’.$txt1.’")’. ‘]’.'[not(ancestor::a)][not(ancestor::h2)][not(ancestor::h3)]’); I have an HTML document containing multiple H2 tags. I do not want to match the whole HTML document just till ..

Read more

Let’s say I have the following .xml file: <?xml version="1.0" encoding="UTF-8"?> <root> <item> <name>Foo</name> </item> <item> <name>Bar</name> </item> </root> In this sample file, I’m trying to append new nodes <item> to node <root> after the last node <item>. I’m trying to append newly created <item> nodes after the last <item> node in the <root> node ..

Read more

I’m generating an XML file via PHP and I’m doing it this way: $dom = new DOMDocument(); $root = $dom->createElement(‘Root’); … // some node definitions here etc $root->appendChild($product); $root->appendChild($quantity); $root->appendChild($measureUnit); $root->appendChild($lineNumber); … $dom->appendChild($root); $dom->save( ‘/some/dir/some-name.xml’); It all works well but I just encountered some problem when I get to the part that I needed to ..

Read more

I have an HTML code where there are attributes like @click, @autocomplete:change used by some JS libraries. When I parse the HTML using DOMDocument, these attributes are removed. Sample code: <?php $content = <<<‘EOT’ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head></head> <body> <a role="tab" @click="activeType=listingType"></a> <input type="text" @autocomplete:change="handleAutocomplete"> </body> </html> EOT; // creating new document $doc ..

Read more

I have a problem with DOMDocument class. I need to pass to DOMDocument::createElement method HTML as a value of element. I have, a class which builds a schedule for events and one method of this class have the code like that: $label = $this->list->createElement(‘label’, $this->getEventDescription($event)); Like you see I’m creating label with event description, but ..

Read more