domdocument

PHP DOMDocument get text between two SETS of tags

百般思念 提交于 2019-12-23 05:25:13
问题 Is there a way to use Xpath to parse text between two SETS of tags? For example, see example: <div class="par"> <p class="pp"> <span class="dv">1 </span>Blah blah blah blah. <span class="dv">2 </span> Yada yada yada yada. <span class="dv">3 </span>Foo foo foo foo. </p> </div> <div class="par"> <p class="pp"> <span class="dv">4 </span>Hmm hmm hmm hmm. </p> </div> I want to parse to get an array like below by getting the text between the sets of SPAN tags: array[0] = "Blah blah blah blah.";

Basic DOMXpath, can be wrong? (re: check input namespace always)

耗尽温柔 提交于 2019-12-23 04:34:00
问题 I am using a internal domDocument into a class, $this->doc->dom , and I think that is ok because $this->doc->dom->saveXML() works, and show my XML, something like <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>04</title> <link href="css/04.css" rel="stylesheet" type="text/css"/> </head> ... And when I use $xpath = new DOMXpath($this->doc->dom); $elements =

Salesforce/PHP - outbound messages (SOAP) - memory limit issue? DOMDocument::loadXML() Premature end of data in tag issue?

痴心易碎 提交于 2019-12-23 04:22:51
问题 UPDATE: OK I figured it out, looks like fread has a filesize limitation, changed this to file_get_contents('php://input') , but now having SF give a java.net.SocketTimeoutException: Read timed out error and nothing on the PHP side. I have also added set_time_limit(0); to the PHP script which if I understand correctly execute the script for as long as it takes. Any thoughts? BTW: I can process up to 25 (that I've tested) but not 100 I'm using Salesforce to send outbound messages (via SOAP) to

DOMDocument need to search for an element that has attribute class=“something”

旧时模样 提交于 2019-12-23 04:12:38
问题 In PHP I'm using DOMDocument and I need to search for an element that has attribute class="something" I'm new with DOMDocument (been using REGEX all my life so help me :P) Ok, my question is, I've found a DOMElement using getElementById, now i want to look inside the children of this element and retrieve a node that has a particular class, class="something" How do i do that? 回答1: Once you have a DOMNode $n for a document $d whose children you want to filter by class you can do (this searches

PHP remove multiple elements with dom

a 夏天 提交于 2019-12-23 03:44:28
问题 I'm trying to remove multiple elements in php using DOM Document, but it does not work as i wanted it to work. <iPhone> <enAttentePush> <UDID>dd6fc8032f0bf4c4b3a9c60f523900c9ad463b620a83b6473eda9a12b2c9d47f</UDID> <Message>someDataHere</Message> </enAttentePush> <enAttentePush> <UDID>dd6fc8032f0bf4c4b3a9c60f523900c9ad463b620a83b6473eda9a12b2c9d47f</UDID> <Message>someDataHere</Message> </enAttentePush> </iPhone> I want to loop into my xml document and then erase all element to get an empty

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

穿精又带淫゛_ 提交于 2019-12-23 03:38:18
问题 I need to parse hundreds of XML files having all the same structure as follows: <?xml version="1.0" encoding="UTF-8"?> <Concepts> <ConceptModel name="food"> <Filters> <Filter type="CC"/> </Filters> <Queries> <Query lang="EN">(cheese, bread, wine)</Query> <Query lang="DE">(Käse, Brot, Wein)</Query> <Query lang="FR">(fromaige, pain, vin)</Query> </Queries> </ConceptModel> </Concepts> I have read several articles and posts in internet like below but I could not come up with a solution: Excel vba

DOMDocument & XPath - HTML Tag of each Node

六月ゝ 毕业季﹏ 提交于 2019-12-23 02:32:17
问题 Given the following PHP code using DOMDocument: $inputs = $xpath->query('//input | //select | //textarea', $form); if ($inputs->length > 0) { for ($j = 0; $j < $inputs->length; $j++) { $input = $inputs->item($j); $input->getAttribute('name'); // Returns the Attribute $input->getTag(); // How can I get the input, select or textarea tag? } } How can I know the tag name of each matched node? 回答1: $inputs = $xpath->query('//input | //select | //textarea', $form); // no need for "if ($inputs-

nodeValue from DomDocument returning weird characters in PHP

对着背影说爱祢 提交于 2019-12-22 18:26:09
问题 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 response: "aujourd’hui". Thanks in advance. 回答1: I had the same issues and now noticed that loadHTML() no longer takes 2 parameters, so I had to find a

DOMDocument::loadHTMLFile() modify user agent

夙愿已清 提交于 2019-12-22 12:09:11
问题 Im using PHP to load a website in a DOM Tree. Is there a way to modify the user agent that is sent using DOMDocument::loadHTMLFile() ? function parseThis($url) { $html = new DOMDocument(); $html->loadHtmlFile( $url ); return $html } 回答1: Change the user_agent value in php.ini , which should be sent in anything making use of the http stream wrapper like DOMDocument::loadHtmlFile(), file_get_contents() , etc. $fake_user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like

XML DomDocument optimization

对着背影说爱祢 提交于 2019-12-22 11:04:19
问题 I have a 5MB xml file I'm using the following code to get all nodeValue $dom = new DomDocument('1.0', 'UTF-8'); if(!$dom->load($url)) return; $games = $dom->getElementsByTagName("game"); foreach($games as $game) { } This takes 76 seconds and there are around 2000 games tag. Is there any optimization or other solution to get the data? 回答1: You shouldn't use the Document Object Model on large XML files, it is intended for human readable documents, not big datasets! If you want fast access you