PHP - Problem Reading Xml Attributes With Php Xpath Function
<league name="italy" id="1">
<match name="AC Milan v Palermo" time="15/02/2011 20:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="AC Milan" odd="1.87"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="Palermo" odd="4.00"> </bettype> </match> <match name="Juventus v Torino" time="15/02/2011 20:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="Juventus" odd="2.00"> <bet outcome_name="X" odd="3.00"> <bet outcome_name="Torino" odd="2.00"> </bettype> <bettype name="Half Time"> <bet outcome_name="1" odd="2.40"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="2" odd="1.40"> </bettype> </match> </league> <league name="Spain" id="2"> <match name="Barcelona v Real Madrid" time="15/03/2011 21:45"> <bettype name="Versus (with Draw)"> <bet outcome_name="Barcelona" odd="1.87"> <bet outcome_name="X" odd="3.40"> <bet outcome_name="Real Madrid" odd="4.00"> </bettype> </match> </league> im trying to parse attributes of above xml with using xpath functions. what i want to output is this: ( <bettype name="Half Time"> this will be ignored ) Italy AC Milan v Palermo 1.87 3.40 4.00 Juventus v Torino 2.00 3.00 2.00 spain Barcelona v Real Madrid 1.87 3.40 4.00 im trying do this with below xpath codes $xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml'); $league=$xml->xpath("//league"); $matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); $odds=$xml->xpath('//match/bettype[@name="Versus (with Draw)"]/bet'); i searched and tried lots of tutorials. i need help in writing the correct code thanks Similar TutorialsHi all, I'm sure I'm making this far more difficult than I need to... I've got an xml document... <library id="1"> <lname>Lib1</name> <book id="1"> <title>book 1</title> <author>Author 1</author> </book> <book id="2"> <title>book 2</title> <author>Author 2</author> </book> </library> I can access the nested elements using xpath like : $result = $xml->xpath('//book'); foreach($result as $books) { echo $books->title; } How would I do this for the attributes? If I specify I want the attributes in the xpath query I can't get at the elements... I'm trying to turn this xml file into a simple relational database... A library table and a book table. So I need the library id (attribute) and the name(nested element) for one insert query - and the book id, title, author and the library id for the other. Anyone got any idea? Cheers John Hi everyone, I am having trouble with the last() function in xpath . I want to get the text3. The HTML looks like this: Code: [Select] div id="body"> <br> <br> text1 <hr> text2 <br> <br> text3 So far I have: Code: [Select] $lastdata= $simplexml->xpath("//div[@id='body']/following-sibling::node [last()]"); This is not working. I would appreciate any help. Thank you in advance, Bill So here's what I'm trying to do, and I haven't found any clear tutorials on how to properly navigate a DOMDocument object, at least not in the strict sense of PHP. I'm building a web scraper, I've had it working for some time now using more traditional methods (a combination of string manipulation and clever regex). I've been told xpath can be much faster and more reliable for what I need. Sold. Let's say I'm parsing a forum. This forum separates each reply in a post with a set of <li></li> with a class of "message" Code: [Select] <li class="message"> // Stuff here </li> <li class="message"> // Stuff here </li> So far so good. These list items contain all the formatting for each post, including user info and the message text. Each sitting in it's own div. Code: [Select] <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> <li class="message"> <div class="user info"> User info here </div> <div class="message text"> Message text here </div> </li> Still with me? Good. With this bit of code I can select each message list item block and iterate over all the sub nodes inside. Code: [Select] $items = $xpath->query("//li[starts-with(@class, 'message')]"); for ($i = 0; $i < $items->length; $i++) { echo $items->item($i)->nodeValue . "\n"; } This produces a basic text dump of the entire forum. Close, but not what I need. What I'm trying to do is as follows Select all the class="message" list items [done] Once those have been selected, run another $xpath->query to select the child nodes which contain the user info and message text Step one is done, step two is what is confusing me. How can I run a new query based on the output from the first query? Thanks guys Hi, I have been trying to improve my PHP programming skills by following the Lynda.com Beyond the basics tutorial and they came to a section where they were building common database methods inside a database class. Since they did not have PHP 5.3 (Where late static bindings is introduced) they had to place code referring to self:: inside of each class that needs this functionality. It seems that not having late static binding was binding self to the database class and not to other classes that call it statically. I will insert some code to explain this better. Long story short, I was really interesting in getting an attributes function working and as I do not have late static bindg either, I cannot figure out how to call it from inside a class to make it function correctly. Here is some code. Below is the attribute class they wrote. Each class declared an array of attributes for each of the classes that want to call this method like protected static $db_fields = array('id', 'email', 'password', 'etc'); Code: [Select] protected function attributes() { // return an array of attribute names and their values $attributes = array(); foreach(self::$db_fields as $field) { if(property_exists($this, $field)) { $attributes[$field] = $this->$field; } } return $attributes; } They planned on moving this code to a DatabaseObject class after they get LSB but until then, have to include it in every class that wants use this. Is there any way to write this as a function, include it in a class, and call the method without late static binding.. or even place this inside a database class and call it from another class without LSB? Forgive me if I am not explaining this correctly, again, I am still learning. My version of PHP is 5.2.6. I am trying to write a more elegant solution to be able to check an object, find only the properties in an object that have values, and update those values in a database with a matching ID. I am extending a class from a generic user class here is an example of my code Code: [Select] <?php require_once('User.php'); require_once('Database.php'); class Vendor extends User { protected static $vendor_attributes = array('id', 'nothing' , 'tagline' , 'bio'); protected static $table_name = "user_vendors"; public $tagline; }//close class ?> I have 4 websites http://www.mercurymagazines.com/pr1/101/101395 http://www.mercurymagazines.com/pr1/169/16000 http://www.mercurymagazines.com/pr1/101/101396 http://www.mercurymagazines.com/pr1/169/16001 I am trying to write a program that will open each webpage one at a time, look for a unique word such as 'FREE' and if it is found the write the URL to a file, if not then no output and the next webpage is opened. I know this word exists only on one of the pages above (http://www.mercurymagazines.com/pr1/101/101396). When http://www.mercurymagazines.com/pr1/101/101396 appears last in the list located in source.txt the programs WORKS. When http://www.mercurymagazines.com/pr1/101/101396 appears in any other position such as first, or second, the program does NOT work. My head is sore from banging against my desk. Any assistance would be appreciated. <?php $file_source = fopen("source.txt", "r"); $file_target = fopen("targets.txt", "w"); while (!feof($file_source) ) { $url = fgets($file_source); echo '<br>'.$url; $raw_text = file_get_contents($url); mb_regex_encoding( "utf-8" ); $words = mb_split( ' +', $raw_text ); foreach ($words as $uniques) { echo $uniques; if ($uniques == 'FREE') { fwrite($file_target, $url); } } } ?> Hi What I need to do is retrieve information from a web form, that contains a file id, and which options from check boxes have been ticked. The code in the web form is. Code: [Select] <td width=\"206\"><p>$filename1<br><img src=\"$filename1\" alt=\"$filename1\" /></p> <p> <label> <input type=\"checkbox\" name=\"image_id[$unique_id1][save]\" value=\"save\" id=\"CheckboxGroup1_1\" /> Save</label> <br /> <label> <input type=\"checkbox\" name=\"image_id[$unique_id1][delete]\" value=\"delete\" id=\"CheckboxGroup1_2\" /> Delete</label> <br><label> <input type=\"checkbox\" name=\"image_id[$unique_id1][rotate]\" value=\"rotate\" id=\"CheckboxGroup1_3\" /> Image needs rotating</label> <br /> </p></td> This returns the following when I do a Code: [Select] var_dump of $_POST['image_id'][/code] when all three boxes are ticked. Code: [Select] array(1) { [4600]=> array(3) { ["save"]=> string(4) "save" ["delete"]=> string(6) "delete" ["rotate"]=> string(6) "rotate" } } the format is as follows 4600 is the file ID, the 3 others are save, delete, and rotate It appears to work ok, but I can't get at the data easily I can get the key using key(), but I can't get the other bits of data out using a foreach loop. Code: [Select] if(isset($_POST['image_id'])) { $file_info = $_POST['image_id']; if (isset($file_info)) { var_dump($_POST['image_id']); while($element = current(file_info)) { echo "<br> Loop = " . key($file_info)."\n"; $index_key = key($file_info); foreach ($dog1 as $index_key => $value) { Echo "<br> foreach value = $value"; } next($file_info); } } } I'm wondering if the array that is being sent back is ok as I tried to creat an array that sent back the same and couldn't, so maybe my code in the form needs changing. OK, so I am trying to read exif data from images and have come up against a snag that I cannot see the answer to. I know that what I have at present is pretty basic, but I want to be sure that I know how to access the bits I want before tidying it up into something more sophisticated. The coide I have is this:- Code: [Select] $exif = exif_read_data('brass jaw.jpg', 'EXIF'); $name = $exif['FileName']; $height = $exif['ExifImageWidth']; $width = $exif['ExifImageLength']; $model = $exif['Model']; $exposuretime = $exif['ExposureTime']; $fnumber = $exif['FNumber']; $iso = $exif['ISOSpeedRatings']; $date = $exif['DateTime']; echo "File Name: $name<br />"; echo "Height: $height<br />"; echo "Width: $width<br />"; echo "Camera: $model<br />"; echo "Shutter Speed: $exposuretime<br />"; echo "F number: $fnumber<br />"; echo "ISO: $iso<br />"; echo "Date & Time: $date<br />"; var_dump($exif); This code produces the following:- File Name: brass jaw.jpg Height: 640 Width: 360 Camera: Canon EOS 550D Shutter Speed: 244/1000000 F number: 8000000/1000000 ISO: Array Date & Time: 2011:09:17 13:52:30 Which serves quite well apart from the ISO, which comes back as "Array". Now when I do a var_dump I see that ISOSpeedRatings returns as this:- 'ISOSpeedRatings' => array 0 => int 800 1 => int 800 What I can't work out is how to access the information from this - I know that the solution will probably be very simple, and that I will end up kicking myself, but I could use a little help. My parser: <?php if (isset($_GET['formSubmit'])) { $option = $_GET['option']; $option = array_values($option); if (!empty($option)){ $xml = simplexml_load_file('differences.xml'); $i = 0; $count = count($option); ?> <table> <tr> <td>Item</td> <td>Code</td> <td>Type</td> <td>Level</td> </tr> <?php while($i < $count) { $selected = $xml->xpath("//item[contains(@name,'".$option[$i]."')]"); echo "<tr>"; echo "<td>".$selected[0]['name']."</td>"; echo "<td>".$selected[0]['code']."</td>"; echo "<td>".$selected[0]['type']."</td>"; echo "<td>".$selected[0]['requiredLevel']."</td>"; echo "</tr>"; $i++; } ?> </table> This works great however requiredLevel is showing nothing. Here is what is stored in the $selected array: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [buildingName] => EiffelTower [code] => lM [type] => building ) [requiredLevel] => 5 [cost] => 5000 [built] => 03/31/1889 => SimpleXMLElement Object ( [@attributes] => Array ( [itemClass] => EiffelTower_construct ) ) [defaultItem] => SimpleXMLElement Object ( [@attributes] => Array ( [amount] => 1 [name] => iron ) ) [finishedReward] => iron [image] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_0 [url] => /buildings/eiffel_tower.swf ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => construct_1 [url] => /buildings/eiffel_tower.swf ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [loadClass] => mc [name] => built_0 [url] => /buildings/eiffel_tower.swf ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => icon [url] => buildings/eiffel_tower.png ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => startIcon [url] => /buildings/eiffel_tower.png ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => halfIcon [url] => /buildings/eiffel_tower.png ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => completeIcon [url] => /buildings/eiffel_tower.png ) ) ) [constructionUI] => /buildings/Construct_eiffel_tower.swf [countryCard] => france ) My XML: <element> <item code="lM" name="snowman2010" type="building"> <requiredLevel>5</requiredLevel> <cost>5000</cost> <built>03/31/1889</built> <storageType itemClass="EiffelTower_construct"/> <defaultItem amount="1" name="iron"/> <finishedReward>iron</finishedReward> <image loadClass="mc" name="construct_0" url="/buildings/eiffel_tower.swf"/> <image loadClass="mc" name="construct_1" url="/buildings/eiffel_tower.swf"/> <image loadClass="mc" name="built_0" url="/buildings/eiffel_tower.swf"/> <image name="icon" url="/buildings/eiffel_tower.png"/> <image name="startIcon" url="/buildings/eiffel_tower.png"/> <image name="halfIcon" url="/buildings/eiffel_tower.png"/> <image name="completeIcon" url="/buildings/eiffel_tower.png"/> <constructionUI>/buildings/eiffel_tower.swf</constructionUI> <countryCard>france</countryCard> </item> Using the established code pattern in my parser.php how can I print out requiredLevel? The output of my array is mighty confusing! [/code] Hi all, I am pretty new to php and I am having an issue trying to load an XML document. When ever I try to use Xpath it negates all the code below the line, including the HTML, and returns a white page. here is my code: Code: [Select] <html> <head> <?php $xpath = new DOMXPath("structure.xml"); ?> <body> hello world </body> </html> I checked phpinfo() and I have both the DOM and XPath enables and installed. I have also tried using just DOM and that worked so it is only Xpath that is not working. Ideas? Thank you James S I am having trouble obtaining the second table in this HTML code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><html> <head> <meta http-equiv="Pragma" content="no-cache"> <title>Entity Information</title> <link rel="stylesheet" href="documents/CORP/default.css" media="screen" type="text/css"> <link rel="stylesheet" href="documents/CORP/infotable.css" media="screen" type="text/css"> </head> <body> <div class="headings"> <h1 class="dos_heading1">Company Information </h1> <BR> <h2 class="dos_heading2"> </h2> <h3 class="page_heading">Company Information</h3> <p class="DtMsg">The information contained in this database is current through September 10, 2010.</p> </div> <hr noshade width="100%"> <center> <div class="highlight">Selected Company Name: 1 PARK ROW, LLC</div> <table summary="This table contains status information for the selected entity."> <caption> Selected Company Status Information </caption> <tr> <th>Current Company Name:</th> <td>1 PARK ROW, LLC</td> </tr> <tr> <th>Initial Filing Date:</th> <td>JANUARY 22, 1997</td> </tr> <tr> <th>County:</th> <td>NASSAU</td> </tr> <tr> <th>Jurisdiction:</th> <td>NEW JERSEY </td> </tr> <tr> <th>Entity Type:</th> <td>DOMESTIC LIMITED LIABILITY COMPANY</td> </tr> <tr> <th>Current Company Status:</th> <td>ACTIVE </td> </tr> </table> <BR> <table id="tblAddr" summary="This table contains address information for the selected entity."> <caption>Selected Entity Address Information</caption> <tr> <th scope="col" id="c1" class="leftalign"><span class="rmvbold">Address</span></th> </tr> <tr> <td headers="c1"> C/O ELECTRONICS INC.<br> 2355 PARK ROW<br> NEW BRUNSWICK, NEW YORK, 15538 </td> </tr> <tr> <th scope="col" id="c4" class="leftalign">Registered Agent</th> </tr> <tr> <td headers="c1"> NONE </td> </tr> </table> <br> <p style="width:50%"> </p> <div id="divStockContainer"> <h4 id="capStock">*Stock Information</h4> <div id="divStock"> <table id="tblStock" cellpadding="0" cellspacing="6"> <tr> <th># of Shares</th> <th>Type of Stock</th> <th>$ Value per Share</th> </tr> <tr> <td> </td> <td>No Information Available</td> <td> </td> </tr> </table> </div> <p id="pStockBlurb">*Stock information is applicable to domestic business corporations.</p> </div> <div id="divHistNmContainer"> <h4 id="capNmHist">Name History</h4> <div id="divNmHist"> <table id="tblNameHist" cellpadding="0" cellspacing="6"> <tr> <th class="FileDt">Filing Date</th> <th class="NameType">Name Type</th> <th class="CorpName">Company Name</th> </tr> <tr> <td class="FileDt">JAN 22, 1997</td> <td class="NameType">Actual</td> <td class="CorpName">1 PARK ROW, LLC</td> </tr> </table> </div> <p id="pFictName"> </p> </div> </center> </body> </html> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script></script> I can get the top part with this: /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ $dom->loadHTML($html2); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom->getElementsByTagName('table'); /*** get all rows from the table ***/ $rows = $tables->item(0)->getElementsByTagName('tr'); /*** loop over the table rows ***/ foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('td'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; echo $cols->item(1)->nodeValue.'<br />'; echo $cols->item(2)->nodeValue; echo '<hr />'; } } Any help would be appreciated I dont even know where to start to echo the 2nd table in the html. Thanks. Code: [Select] $domdoc=new DOMDocument(); $domdoc->formatOutput=TRUE; $empty_cart_xml= '<Order> <Cart> <Items> <Item>1</Item> <Item>2</Item> <Item>3</Item> </Items> </Cart> </Order>'; $domdoc->loadXML($empty_cart_xml); print $domdoc->saveXML()."<hr/>"; //works up to this point $xpath=new DOMXPath($domdoc); $items=$xpath->query('Order/Cart/Items'); foreach($itemses AS $items) { $items->appendChild($domdoc->createElement('Item','4')); } print $domdoc->saveXML(); All I want to do is to add a new Item to Items. What am I doing wrong? Hi all I am trying to get the lat and long properties from the googlemaps geocoding api. $xml=simplexml_load_file($url); if ($xml === false) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) { echo "\t", $error->message; } } else{ $path = $xml->xpath( "/GeocodeResponse/result/geometry/location"); $lat = $path->lat; $lng = $path->lng; echo $lat; echo $lng; $sql1 = "UPDATE tbl_clubs set lat='$lat',lng='$lng' where club_id =$id"; echo $sql1; $result1 = mysqli_query($dbConn,$sql1) or die($mysqli_error($dbConn)); } This is the XML I am using <GeocodeResponse> <status>OK</status> <result> <type>establishment</type> <type>point_of_interest</type> <type>stadium</type> <formatted_address>Aldridge Rd, Perry Barr, Birmingham B42 2ET, UK</formatted_address> <address_component> </address_component> <address_component> </address_component> <address_component> </address_component> <address_component> <long_name>West Midlands</long_name> <short_name>West Midlands</short_name> <type>administrative_area_level_2</type> <type>political</type> </address_component> <address_component> <long_name>England</long_name> <short_name>England</short_name> <type>administrative_area_level_1</type> <type>political</type> </address_component> <address_component> <long_name>United Kingdom</long_name> <short_name>GB</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>B42 2ET</long_name> <short_name>B42 2ET</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>52.5196698</lat> <lng>-1.8986236</lng> </location> <location_type>GEOMETRIC_CENTER</location_type> <viewport> <southwest> <lat>52.5183208</lat> <lng>-1.8999726</lng> </southwest> <northeast> <lat>52.5210188</lat> <lng>-1.8972746</lng> </northeast> </viewport> </geometry>
But I am getting the following response Notice: Trying to get property of non-object in /home/sites/1a/9/95f15f28a6/public_html/results/getLatLng.php on line 22 I am guessing my path is wrong, any guidance would be great I am trying to parse a blogspot feed using xpath but it doesnt seem to be working with anything that I try. I am not sure if it is because of the namespaces or what but I was hoping someone could help me. Here is the code: $xml = simplexml_load_file('http://feeds.feedburner.com/blogspot/MKuf'); $next = $xml->xpath("//link[@rel='next']"); print_r($next); This is just returning an empty array and it should not be. I tried it doing just link or just entry and it still is returning empty. The only one I can run on it that works is *. Any help is appreciated. Hello, I recently moved hosts and upgraded to PHP 7.4.10. Suddenly, one of my sites is having issues with XSL views. The software creator claims this is an issue with XSL in PHP. I am unsure of what to check to troubleshoot this. Would anyone have an opinion on my issue? If not, please let me know if I should be posting somewhere else altogether. Thanks in advance - Quote
xmlXPathCompOpEval: function function not found The view.xsl file: Quote
<xsl:value-of select="php:function( 'SobiPro::AlternateLink', $rssUrl, 'application/atom+xml', $sectionName )"/>
good evening dear php-freaks,
hope you are all right.
My tactic is as follows:
1. i run requests to the openstreetmap-endpoint- (see below) and i try three different APIs per request isn't that easy on ressources and 2. I don't know how to work with the results that i gather from the OpenStreetmap-Endpoint
as of the first point: - workin on the endpoint of OSM-Overpass-API.... see my approach: <?php /** * OSM Overpass API with PHP SimpleXML / XPath * * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets) */ // // 1.) Query an OSM Overpass API Endpoint // $query = 'node ["amenity"~".*"] (38.415938460513274,16.06338500976562,39.52205163048525,17.51220703125); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($query), ]]); # please do not stress this service, this example is for demonstration purposes only. $endpoint = 'http://overpass-api.de/api/interpreter'; libxml_set_streams_context($context); $start = microtime(true); $result = simplexml_load_file($endpoint); printf("Query returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result //
so far so good: with this i get a bunch of data.....
<?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Osmosis SNAPSHOT-r26564" xapi:planetDate="2014-10-07T15:42:02Z" xmlns:xapi="http://jxapi.openstreetmap.org/"> <node id="251652819" version="6" timestamp="2013-10-19T14:03:10Z" uid="1198089" user="GeorgeKaplan" changeset="18434238" lat="48.8527413" lon="2.3333559"> <tag k="dispensing" v="yes"/> <tag k="website" v="http://www.pharmacie-paris-citypharma.fr/"/> <tag k="name" v="Pharmacie Citypharma in downtown paris"/> <tag k="amenity" v="pharmacy"/> </node> <node id="251774849" version="9" timestamp="2014-07-28T21:28:26Z" uid="92075" user="Art Penteur" changeset="24411346" lat="48.8468043" lon="2.3696423"> <tag k="phone" v="0143430996"/> <tag k="dispensing" v="yes"/> <tag k="name" v="Pharmacie de la Rapée in downtown paris"/> <tag k="amenity" v="pharmacy"/> <tag k="opening_hours" v="Mo-Fr 08:30-20:30; Sa 09:00-19:30"/> </node> <node id="263262912" version="3" timestamp="2014-07-28T21:37:24Z" uid="92075" user="Art Penteur" changeset="24411346" lat="48.8446917" lon="2.3101829"> <tag k="dispensing" v="yes"/> <tag k="amenity" v="pharmacy"/> </node>
what is aimed: I am trying to filter the records based on the attributes that i find in the dataset, <tag k="name" v="blahblahblah"/> field.
I have been looking around and the classical way to do it its easy, however because of my poor skills in doing anything Is it possible to apply xml filtering for tags that look like this <tag k="dispensing" v="yes"/> ones that do not have the <tag></tag>
.....format. Also how can i filter the records when each child of the node has different attributes,like v, <tag k="name">Pharmacie in Paris-downtown - Rapée-metro-station</tag>
i have had a quick look at the PHP-SimpleXML and the XPath-approach: it may help me in achieving what is aimed.
but at the moment - i think i got stuck.
i greatly appreciated hints and some ideas that may fit her.
have a great day. - yours dil_bert Edited December 1, 2019 by dil_bert hi, im trying to parse this xml file : xml.gamebookers.com/sport /football.xml_attr.xml i want to echo on my page like this : league name 1 match 1 of league 1 odds odds odds match 2 of league 1 odds odds odds . . league name 2 match 1 of league 2 odds odds odds match2 of league 2 odds odds odds . . this is my code so far <?php $xml=simplexml_load_file('http://xml.gamebookers.com/sports/football.xml_attr.xml'); $league=$xml->xpath('//event/..'); // leagues refers to element<group> $matches=$xml->xpath('//bettype[@name="Versus (with Draw)"]/..'); // shows matches name (team versus team) $odds=$xml->xpath('//event/bettype[@name="Versus (with Draw)"]/bet'); //odds of matches 1 x 2 $leaguecount=count($league); $matchescount=count($matches); $oddscount=count($odds); $i=0; while ($i<$leaguecount){ echo $league[$i]['name'].'<br>'; $i++; } echo '<br><br>'; $i=0; while ($i<$matchescount){ echo $matches[$i]['name'].'<br>'; $i++; } $i=0; while ($i<$oddscount){ echo $odds[$i]['odd'].'<br>'; $i++; } ?> it prints this: http://www.mh724.com/school/xp.php so i need something like that: echo league[$i][mathces[$i][odds[$i] // like arrays of array but it does not work of course any help will highly appreciated :shrug: with regardS hello dear community, good day,
I've been having an issue trying to parse text in a span cass with DOM. Here is my code example. try to extract some lines out of a webpage - with following technique: with the Extraction of values of attributes of elements with DOMDocument. Here is what i have gathered and learned:
$remote = "http://website.com/"; $doc = new DOMDocument(); @$doc->loadHTMLFile($remote); $xpath = new DOMXpath($doc); $node = $xpath->query('//span[@class="user"]'); echo $node;
and this returns the following
error -> "Catchable fatal error: Object of class DOMNodeList could not be converted to string".
And now - with this i need help.
What I am trying to do is parse the user name between this tag;
<div class="widget plugin-meta"> <h3 class="screen-reader-text">Meta</h3>
see more below:Here the concrete example view-source: https://wordpress.org/plugins/participants-database/ and https://wordpress.org/plugins/participants-database/
goal i need the following data:
Version: Last updated: Active installations: Tested up:
view-source: https://wordpress.org/plugins/participants-database/
Proceedings; i checked the source of the webpage. i tried to find out whether the texte is related to some kind of pattern.i have looked closely and found that all of them have class=”widget plugin-meta” . Well - This will make extracting them, a piece of cake. I tried with the code below helps to filter html elements based on values of attributes. but unfortunatley this ends up in a bad result; i need a helping hand and need to know how to parse the above mentioned data
Version: Last updated: Active installations: Tested up:
Any idea for the starting-point!? I love to hear from you.
|