This is the xml from the WA state DOR web site.
<?xml version="1.0" encoding="UTF-8"?>
<response loccode="3406" localrate="0.024" rate="0.089" code="0">
<addressline houselow="6500" househigh="6598" evenodd="E" street="LINDERSON WAY SW" state="WA" zip="98501" plus4="6561" period="Q12017" code="3406" rta="N" ptba="Thurston PTBA" cez=""/>
<rate name="TUMWATER" code="3406" staterate="0.065" localrate="0.024"/></response>
I've converted it to an array with the PHP command 'simplexml_load_string';
SimpleXMLElement Object
(
[@attributes] => Array
(
[loccode] => 1726
[localrate] => 0.031
[rate] => 0.096
[code] => 0
)
[addressline] => SimpleXMLElement Object
(
[@attributes] => Array
(
[houselow] => 5201
[househigh] => 5299
[evenodd] => O
[street] => 37TH AVE S
[state] => WA
[zip] => 98118
[plus4] => 6115
[period] => Q12017
[code] => 1726
[rta] => Y
[ptba] => King PTBA
[cez] => Duwamish
)
)
[rate] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => SEATTLE
[code] => 1726
[staterate] => 0.065
[localrate] => 0.031
)
)
)
I've been able to pull two elements form the first level and I need an element form the second level. I've searched and tested for over 6 hours on this one. I need help to pull the 'plus4' value from the array or xml. Here's my attempt so far:
<?php
$addr1 = "5211 37th Ave S";
`enter code here`$city = "seattle";
$zip = "98118";
$postdata = array("output"=>"xml", "addr"=>urlencode($addr1), "city"=>urlencode($city), "zip"=>$zip);
$url = "http://dor.wa.gov/AddressRates.aspx";
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST , 1);
curl_setopt($ch, CURLOPT_POSTFIELDS , $postdata);
$return = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($return === FALSE) {
echo "cURL Error: " . curl_error($ch); }
curl_close($ch);
$xml=simplexml_load_string($return) or die("Error: Cannot create object");
echo "Localation Code: " . $xml['loccode'];
echo "<br>Tax Rate: " . $xml['rate'];
echo "<br>" . $xml[1]['plus4'];
?>