domdocument

How to know if a DOMDocument is owned by a parser

余生长醉 提交于 2019-12-25 06:22:20
问题 I am looking into an issue where an API is getting called from two different sources. We have an API called dispatch. Its signature is as follows. DOMDocument* dispatch( DOMDocument * requestDocument ) We observed that this API can be called by passing a DOMDocument object that is A stand-alone DOMDocument object created using DOMImplementation::createDocument http://xerces.apache.org/xerces-c/apiDocs-3/classDOMImplementation.html A parse owned DOMDocument object created using

Creating a lot of DOM elements. which method is faster? Echoing the HTML or using PHP DOM class?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 05:31:29
问题 I need to create about 10k elements when a user visit my site, its sort of a big tree like <ul> and <li> . The process of creating the HTML currently takes about 15 seconds, i create the HTML in an array then json_encode and echo it. i am trying to shorten the process. my question is: would it be faster to use php's DOM class to create the elements. or just create the HTML and echo it? 回答1: 15 seconds to create and json_encode 10K elements .. this can't be right. The bottle neck is

Creating a lot of DOM elements. which method is faster? Echoing the HTML or using PHP DOM class?

走远了吗. 提交于 2019-12-25 05:31:12
问题 I need to create about 10k elements when a user visit my site, its sort of a big tree like <ul> and <li> . The process of creating the HTML currently takes about 15 seconds, i create the HTML in an array then json_encode and echo it. i am trying to shorten the process. my question is: would it be faster to use php's DOM class to create the elements. or just create the HTML and echo it? 回答1: 15 seconds to create and json_encode 10K elements .. this can't be right. The bottle neck is

PHP $xpath->query expression not working

不打扰是莪最后的温柔 提交于 2019-12-25 04:45:15
问题 PHP xpath query not working. any idea? Problem # 1 HTML Source: <tr> <td class="abc pqr xyz">Some contents i want to capture</td> </tr> <tr> <td class="abc pqr xyz">more content i want to capture too</td> </tr> <tr> <td class="abc pqr xyz">all row in this table i want to capture</td> </tr> <tr> <td class="abc pqr xyz">they are all pokemon, i want to capture</td> </tr> PHP i tried: $url = "http://www.example.com/"; $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));

DomXPath with DOMDocument to get <img> Class URL

♀尐吖头ヾ 提交于 2019-12-25 02:59:24
问题 I am writing a little scraper script that will find the image URL that has a particular class name. I know that my cURL and DOMDocument is functioning okay, and even the DomXPath really (as far as I can tell, there are no errors) But I am struggling to work out how to get the URL of the xpath query results. My code so far: $dom = new DOMDocument(); @$dom->loadHTML($x); $xpath = new DomXpath($dom); $div = $xpath->query('//*[@class="productImage"]'); var_dump($div); echo $div->item(0); If I var

Get all leaf from complex XML with attributes

萝らか妹 提交于 2019-12-25 02:48:19
问题 I have that kind of XML file myxml.xml <?xml version="1.0" encoding="utf-8"?> <products nb="2" type="new"> <product ean="12345677654321"> <sku>Product1</sku> <parameters> <short_desc> Short description of the product1 </short_desc> <price currency="USD">19.65</price> </parameters> </product> <product ean="12345644654321"> <sku>Product2</sku> <parameters> <long_desc> Long description of the product2 </long_desc> <price currency="USD">19.65</price> <vat>20</vat> </parameters> </product> <

Preserving line breaks in xml node

ぐ巨炮叔叔 提交于 2019-12-25 01:48:55
问题 I'm trying to convert lines in an XML node into an unordered list, however I'm having some difficulty. Take for example this node : <test> Line1 Line2 Line3 </test> I would like to transform it into this with PHP <ul> <li>Line1</li> <li>Line2</li> <li>Line3</li> </ul> I've tried using DOMDocument and SimpleXML, however neither seem to retain the newlines. When echoed, the node value looks like this : Line1 Line2 Line3 I've also tried explode in order to have an array containing each line as

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

你。 提交于 2019-12-25 01:48:20
问题 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) instead of the php file's real name which is 'backup.php' 回答1: Set the Content-Disposition header as an attachment prior to your echo: <? header('Content-Disposition:

NotSupportedException was unhandled by user code exception

一世执手 提交于 2019-12-25 01:40:02
问题 I'am trying to store a value of Document.cookie into a string variable in my c# code. The idea here is to go through each tab in an Internet Explorer browser and then get the cookie information from the tab. So I have got the following, ShellWindows iExplorerInstances = new ShellWindows(); bool found = false; foreach (InternetExplorer iExplorer in iExplorerInstances) { if (iExplorer.Name == "Internet Explorer") { string cookie = iExplorer.Document.cookie; Now this works upon initial running

php DOMDocument class: node tree

不问归期 提交于 2019-12-25 01:37:37
问题 I want to convert html syntax into a node tree ( <ul> structure). How do I do this using the DOMDocument class? $html = ' <div> <p> <a> </p> </div> '; result: <ul> <li> div <ul> <li> p <ul> <li>a</li> </ul> </li> </ul> </li> </ul> 回答1: <?php $xml = '<div> <p> <a>#</a> </p> </div> '; function xml2array($xml,&$result = '') { foreach($xml->children() as $name => $xmlchild) { xml2array($xmlchild,$result); } $result = "<ul><li>".$xml->getName().$result."</li></ul>"; } $result=''; $dd = xml2array