Search the Community
Showing results for tags 'dom xml'.
-
Hi guys, I am trying to grab some data from an API by using cURL and DOMDocuments. This is what I have: $username="XXXXX"; $password="XXXX"; $base_url="https://xxxxxx.net/api/"; $href_url="resources/120529-0039/workorders"; $ch = curl_init($base_url . $href_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSLVERSION,3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept"=>"application/json")); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($ch); So far so good, at this point if I echo the $result, and look at the source, I would get: <?xml version="1.0" encoding="utf-8"?> <References xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" p3:href="resources/120529-0039/workorders" xmlns:p3="http://www.w3.org/1999/xlink" xmlns="http://xxxxxx.net/Apps/20090225/Entities"> <Link p3:href="workorders/3012-23" p3:title="Brandlarmsprov(mar-dec)" /> <Link p3:href="workorders/3021-27" p3:title="Reservkraft(2:a torsdagen varje månad)" /> <Link p3:href="workorders/4375-1" p3:title="Uppdatering av IBK ritningar efter heltäckande brandlarm." /> </References> I am after the "workorders/3012-23" part. Here it all falls aparat for me, I have been playing around with: $husdjur = new DOMDocument(); $husdjur->loadXML($result); $href = $husdjur->getElementsByTagName('Link')->item(0)->getAttribute('p3:href'); And was able to populate $href with one value, but I want them all. I need the following: $href[0] = "workorders/3012-23" $href[1] = "workorders/3021-27" $href[2] = "workorders/4375-1" and so on... Any thoughts? Thanks!