Ho la seguente struttura html <span class="x">a</span> <br> • first <br> • Second <br> • second <br> • third <br> <br> <span class="x">b</span> Ho bisogno di get tutto il valore del text (separato da virgole) che si verifica tra i nodes span, ovvero primo, secondo, secondo, terzo Come si può fare usando xpath, dom
Sto provando a scorrere un file XML formattato in questo modo: <colors> … </colors> <sets> <settype type="hr" paletteid="2" mand_m_0="0" mand_f_0="0" mand_m_1="0" mand_f_1="0"> <set id="175" gender="M" club="0" colorable="0" selectable="0" preselectable="0"> <part id="996" type="hr" colorable="0" index="0" colorsndex="0"/> </set> … </settype> <settype type="ch" paletteid="3" mand_m_0="1" mand_f_0="1" mand_m_1="0" mand_f_1="1"> <set id="680" gender="F" club="0" colorable="1" selectable="1" preselectable="0"> <part id="17" type="ch" […]
Sto cercando di get il valore da A-1 a xpath in base a un attributo passato. Ho passato l'attributo index dell'unità tramite php da una pagina precedente e sto accedendo tramite GET globale: $value = intval($_GET['index']); l'xml: <UNIT index='1'> <ID>A-1</ID> <MANUFACTURER>testing inc.</MANUFACTURER> </UNIT> <UNIT index='2'> <ID>A-2</ID> <MANUFACTURER>testing inc.</MANUFACTURER> </UNIT> Sto cercando di farlo eco usando: […]
Sto avendo alcuni problemi nell'estrarre i dati che voglio da un object SimpleXMLElement. Ecco le basi del codice che sto usando: curl_setopt( $ch, CURLOPT_URL, $URL ); $html = curl_exec( $ch ); $html = $tidy->parseString( $html, $tc, 'utf8' ); $tidy->cleanRepair(); $html = $tidy->body()->value; $xml = new SimpleXMLElement( $html ); $xml = $xml->xpath( "//ul[@id='wxoptions']/li[3]/a" ); //Your XPATH […]
Questo è il mio codice PHP: <?php error_reporting(E_ALL); ini_set("display_errors",1); ini_set('max_execution_time', 36000); //300 seconds = 5 minutes $url = 'http://www.sportstats.com/soccer/matches/20170815/'; libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadHTMLFile($url); $xpath = new DOMXpath($doc); $data = arrays( 'HomeTeam' => $xpath->evaluate('string(//td[@class="table-home"]/a)'), 'AwayTeam' => $xpath->evaluate('string(//td[contains(@class, "table-away")]/a)'), 'FtScore' => $xpath->evaluate('string(normalize-space(translate(//td[@class="result-neutral"]," " ,"")))'), 'HomeTeamid' => $xpath->evaluate('substring-before(substring-after(substring-after(//td[@class="table-home"]/a/@href, "/soccer/"),"-"),"/")'), 'AwayTeamid' => $xpath->evaluate('substring-before(substring-after(substring-after(//td[@class="table-away"]/a/@href, "/soccer/"),"-"),"/")') ); foreach ($data […]
Ecco la fonte xml: xml Questo è l'xml di un file fxg prodotto da Adobe. Il documento FXG è valido xml e in pratica contiene tutte le informazioni per un documento che può essere modificato. Questa domanda specifica riguarda il text che può essere modificato all'interno di FXG in modo che il contenuto possa cambiare. […]
Ho quel tipo di file XML 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> </products> Vorrei un arrays come questo /products/@nb /products/@type /products/product/@ean /products/product/sku /products/product/parameters/short_desc […]
Sto cercando di recuperare il contenuto di un div in una pagina html usando xpath e domdocument. Questa è la struttura della pagina: <div id="content"> <div class="div1"></div> <span class="span1></span> <p></p> <p></p> <p></p> <p></p> <p></p> <div class="div2"></div> </div> Voglio get solo il contenuto di p, non span e div. Sono venuto attraverso questa espressione xpath .//*[@id='content']/p […]
Sono un programmatore principiante, progettando un ragno che striscia le pagine. La logica va così: ricevi $ url con curl creare un documento dom analizzando i tag href usando xpath memorizzare gli attributi href in $ totalurls (che non sono già lì) aggiornamento di $ url da $ totalurls Il problema è che dopo la […]
Ho un file xml <?xml version="1.0"?> <category> <name>SWEATERS</name> <name>WATCHES</name> <name>PANTS</name> <name>test</name> <name>1</name> </category> Come posso rimuovere il nodo <name>test</name> usando xpath, xquery e php. Ho usato questo codice $name='test; $xmlfile="config/shop_categories.xml"; $xml = simplexml_load_file($xmlfile); $target = $xml->xpath('/category[name="'.trim($name).'"]'); print_r($target[0]); if($target == false) return; $domRef = dom_import_simplexml($target[0]); //Select position 0 in XPath arrays $domRef->parentNode->removeChild($domRef); $dom = new DOMDocument('1.0'); […]