http get XML to json

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

42 Replies - 2610 Views - Last Post: 21 January 2014 - 11:16 AM Rate Topic: -----

#1 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

http get XML to json

Posted 08 January 2014 - 10:38 AM

Hi guys, using the xml file (at the bottom of this post), I need to [GET] All Recorded Crimes by Region using php.

** Note that the JSON response is only illustrated in the first GET

http://www.cems.uwe....imes/6-2013/xml
http://www.cems.uwe....mes/6-2013/json

This should return a list of all crimes by region and the totals for England & Wales.

xml :

<response timestamp="xxxxxxxxxx">
<crimes year="6-2013">
<region id="North East" total="138982" />
<region id="North West" total="444423" />
...
...
<national id="British Transport Police" total="51968" />
<national id="Action Fraud" total="150389" />
<england total="3344716" />
<wales total="173614" />
</crimes>
</response>

json :
{
"response": {
"timestamp": "xxxxxxxxxx",
"crimes": {
"year": "6-2013",
"region": [
{ "id": "North East", "total": "138982" },
{ "id": "North West", "total": "444423" }
....
....
],
"national": [
{ "id": "British Transport Police", "total": "51968" },
{ "id": "Action Fraud", "total": "150389" }
],
"england": { "total": "3344716" },
"wales": { "total": "173614" },
}
}
}

Any help would be greatly appreciated. Here is the xml file to work with:

<?xml version="1.0"?>
<crimes timestamp="1389128063" year="">
  <region id="North East Region">
    <name>North East Region</name>
    <area id="Cleveland">
      <name>Cleveland</name>
      <total_recorded_crime>
        <including_fraud>39,522</including_fraud>
        <excluding_fraud>39,067</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,370">
          <homicide>3</homicide>
          <violence_with_injury>3,737</violence_with_injury>
          <violence_without_injury>2,630</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>563</sexual_offences>
        <robbery>259</robbery>
        <theft_offences total="19,811">
          <burglary total="4,561">
            <domestic>2,054</domestic>
            <non_domestic>2,507</non_domestic>
          </burglary>
          <vehicle_offences>3,329</vehicle_offences>
          <theft_from_the_person>372</theft_from_the_person>
          <bicycle_theft>994</bicycle_theft>
          <shoplifting>5,174</shoplifting>
          <other>5,381</other>
        </theft_offences>
        <criminal_damage_and_arson>7,934</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4180"/>
        <drug_offences>2,116</drug_offences>
        <posession_of_weapons_offences>267</posession_of_weapons_offences>
        <public_order_offences>1,342</public_order_offences>
        <miscellaneous>405</miscellaneous>
        <fraud>455</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Durham">
      <name>Durham</name>
      <total_recorded_crime>
        <including_fraud>29,974</including_fraud>
        <excluding_fraud>29,669</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="4,287">
          <homicide>6</homicide>
          <violence_with_injury>2,420</violence_with_injury>
          <violence_without_injury>1,861</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>360</sexual_offences>
        <robbery>108</robbery>
        <theft_offences total="15,009">
          <burglary total="3,983">
            <domestic>1,385</domestic>
            <non_domestic>2,598</non_domestic>
          </burglary>
          <vehicle_offences>3,355</vehicle_offences>
          <theft_from_the_person>149</theft_from_the_person>
          <bicycle_theft>595</bicycle_theft>
          <shoplifting>2,827</shoplifting>
          <other>4,100</other>
        </theft_offences>
        <criminal_damage_and_arson>6,752</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="2982"/>
        <drug_offences>1,281</drug_offences>
        <posession_of_weapons_offences>218</posession_of_weapons_offences>
        <public_order_offences>1,178</public_order_offences>
        <miscellaneous>476</miscellaneous>
        <fraud>305</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Northumbria">
      <name>Northumbria</name>
      <total_recorded_crime>
        <including_fraud>69,486</including_fraud>
        <excluding_fraud>68,575</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="9,186">
          <homicide>17</homicide>
          <violence_with_injury>6,008</violence_with_injury>
          <violence_without_injury>3,161</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>914</sexual_offences>
        <robbery>465</robbery>
        <theft_offences total="34,506">
          <burglary total="8,514">
            <domestic>3,322</domestic>
            <non_domestic>5,192</non_domestic>
          </burglary>
          <vehicle_offences>6,105</vehicle_offences>
          <theft_from_the_person>1,076</theft_from_the_person>
          <bicycle_theft>1,913</bicycle_theft>
          <shoplifting>8,678</shoplifting>
          <other>8,220</other>
        </theft_offences>
        <criminal_damage_and_arson>14,193</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="9118"/>
        <drug_offences>4,730</drug_offences>
        <posession_of_weapons_offences>633</posession_of_weapons_offences>
        <public_order_offences>2,844</public_order_offences>
        <miscellaneous>1,104</miscellaneous>
        <fraud>911</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="North West Region">
    <name>North West Region</name>
    <area id="Cheshire">
      <name>Cheshire</name>
      <total_recorded_crime>
        <including_fraud>57,908</including_fraud>
        <excluding_fraud>56,685</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="10,882">
          <homicide>5</homicide>
          <violence_with_injury>4,889</violence_with_injury>
          <violence_without_injury>5,988</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>880</sexual_offences>
        <robbery>321</robbery>
        <theft_offences total="28,840">
          <burglary total="6,884">
            <domestic>2,895</domestic>
            <non_domestic>3,989</non_domestic>
          </burglary>
          <vehicle_offences>5,706</vehicle_offences>
          <theft_from_the_person>954</theft_from_the_person>
          <bicycle_theft>1,793</bicycle_theft>
          <shoplifting>6,580</shoplifting>
          <other>6,923</other>
        </theft_offences>
        <criminal_damage_and_arson>9,976</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="6431"/>
        <drug_offences>2,825</drug_offences>
        <posession_of_weapons_offences>260</posession_of_weapons_offences>
        <public_order_offences>2,123</public_order_offences>
        <miscellaneous>578</miscellaneous>
        <fraud>1,223</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Cumbria">
      <name>Cumbria</name>
      <total_recorded_crime>
        <including_fraud>23,286</including_fraud>
        <excluding_fraud>22,970</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="4,454">
          <homicide>6</homicide>
          <violence_with_injury>2,331</violence_with_injury>
          <violence_without_injury>2,117</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>371</sexual_offences>
        <robbery>58</robbery>
        <theft_offences total="9,784">
          <burglary total="2,297">
            <domestic>678</domestic>
            <non_domestic>1,619</non_domestic>
          </burglary>
          <vehicle_offences>1,571</vehicle_offences>
          <theft_from_the_person>137</theft_from_the_person>
          <bicycle_theft>432</bicycle_theft>
          <shoplifting>2,459</shoplifting>
          <other>2,888</other>
        </theft_offences>
        <criminal_damage_and_arson>5,290</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="2998"/>
        <drug_offences>1,531</drug_offences>
        <posession_of_weapons_offences>143</posession_of_weapons_offences>
        <public_order_offences>1,008</public_order_offences>
        <miscellaneous>331</miscellaneous>
        <fraud>316</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Greater Manchester">
      <name>Greater Manchester</name>
      <total_recorded_crime>
        <including_fraud>178,857</including_fraud>
        <excluding_fraud>176,276</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="27,933">
          <homicide>36</homicide>
          <violence_with_injury>14,293</violence_with_injury>
          <violence_without_injury>13,604</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>2,940</sexual_offences>
        <robbery>3,898</robbery>
        <theft_offences total="94,336">
          <burglary total="28,363">
            <domestic>15,348</domestic>
            <non_domestic>13,015</non_domestic>
          </burglary>
          <vehicle_offences>20,700</vehicle_offences>
          <theft_from_the_person>5,456</theft_from_the_person>
          <bicycle_theft>4,518</bicycle_theft>
          <shoplifting>13,889</shoplifting>
          <other>21,410</other>
        </theft_offences>
        <criminal_damage_and_arson>28,765</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="19079"/>
        <drug_offences>9,004</drug_offences>
        <posession_of_weapons_offences>1,063</posession_of_weapons_offences>
        <public_order_offences>6,431</public_order_offences>
        <miscellaneous>1,906</miscellaneous>
        <fraud>2,581</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Lancashire">
      <name>Lancashire</name>
      <total_recorded_crime>
        <including_fraud>93,427</including_fraud>
        <excluding_fraud>91,604</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="18,562">
          <homicide>14</homicide>
          <violence_with_injury>10,654</violence_with_injury>
          <violence_without_injury>7,894</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,738</sexual_offences>
        <robbery>626</robbery>
        <theft_offences total="46,045">
          <burglary total="11,856">
            <domestic>4,321</domestic>
            <non_domestic>7,535</non_domestic>
          </burglary>
          <vehicle_offences>8,527</vehicle_offences>
          <theft_from_the_person>958</theft_from_the_person>
          <bicycle_theft>2,135</bicycle_theft>
          <shoplifting>8,286</shoplifting>
          <other>14,283</other>
        </theft_offences>
        <criminal_damage_and_arson>16,589</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="8916"/>
        <drug_offences>3,961</drug_offences>
        <posession_of_weapons_offences>514</posession_of_weapons_offences>
        <public_order_offences>2,618</public_order_offences>
        <miscellaneous>951</miscellaneous>
        <fraud>1,823</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Merseyside">
      <name>Merseyside</name>
      <total_recorded_crime>
        <including_fraud>90,945</including_fraud>
        <excluding_fraud>89,316</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="11,323">
          <homicide>12</homicide>
          <violence_with_injury>6,536</violence_with_injury>
          <violence_without_injury>4,775</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,338</sexual_offences>
        <robbery>1,223</robbery>
        <theft_offences total="43,482">
          <burglary total="11,574">
            <domestic>6,419</domestic>
            <non_domestic>5,155</non_domestic>
          </burglary>
          <vehicle_offences>8,668</vehicle_offences>
          <theft_from_the_person>2,518</theft_from_the_person>
          <bicycle_theft>1,692</bicycle_theft>
          <shoplifting>9,180</shoplifting>
          <other>9,850</other>
        </theft_offences>
        <criminal_damage_and_arson>17,013</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="15610"/>
        <drug_offences>10,169</drug_offences>
        <posession_of_weapons_offences>663</posession_of_weapons_offences>
        <public_order_offences>3,149</public_order_offences>
        <miscellaneous>956</miscellaneous>
        <fraud>1,629</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="Yorkshire and Humber Region">
    <name>Yorkshire and Humber Region</name>
    <area id="Humberside">
      <name>Humberside</name>
      <total_recorded_crime>
        <including_fraud>64,707</including_fraud>
        <excluding_fraud>63,492</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="11,461">
          <homicide>6</homicide>
          <violence_with_injury>6,811</violence_with_injury>
          <violence_without_injury>4,644</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,219</sexual_offences>
        <robbery>479</robbery>
        <theft_offences total="33,016">
          <burglary total="10,120">
            <domestic>3,832</domestic>
            <non_domestic>6,288</non_domestic>
          </burglary>
          <vehicle_offences>4,834</vehicle_offences>
          <theft_from_the_person>581</theft_from_the_person>
          <bicycle_theft>2,332</bicycle_theft>
          <shoplifting>6,844</shoplifting>
          <other>8,305</other>
        </theft_offences>
        <criminal_damage_and_arson>11,020</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="6674"/>
        <drug_offences>2,459</drug_offences>
        <posession_of_weapons_offences>277</posession_of_weapons_offences>
        <public_order_offences>2,723</public_order_offences>
        <miscellaneous>838</miscellaneous>
        <fraud>1,215</fraud>
      </other_crimes_against_society>
    </area>
    <area id="North Yorkshire">
      <name>North Yorkshire</name>
      <total_recorded_crime>
        <including_fraud>34,801</including_fraud>
        <excluding_fraud>33,901</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,009">
          <homicide>5</homicide>
          <violence_with_injury>3,548</violence_with_injury>
          <violence_without_injury>2,456</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>666</sexual_offences>
        <robbery>123</robbery>
        <theft_offences total="17,605">
          <burglary total="4,313">
            <domestic>1,619</domestic>
            <non_domestic>2,694</non_domestic>
          </burglary>
          <vehicle_offences>2,689</vehicle_offences>
          <theft_from_the_person>477</theft_from_the_person>
          <bicycle_theft>1,179</bicycle_theft>
          <shoplifting>3,722</shoplifting>
          <other>5,225</other>
        </theft_offences>
        <criminal_damage_and_arson>5,867</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4061"/>
        <drug_offences>1,862</drug_offences>
        <posession_of_weapons_offences>178</posession_of_weapons_offences>
        <public_order_offences>1,121</public_order_offences>
        <miscellaneous>470</miscellaneous>
        <fraud>900</fraud>
      </other_crimes_against_society>
    </area>
    <area id="South Yorkshire">
      <name>South Yorkshire</name>
      <total_recorded_crime>
        <including_fraud>93,116</including_fraud>
        <excluding_fraud>91,437</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="10,450">
          <homicide>18</homicide>
          <violence_with_injury>7,313</violence_with_injury>
          <violence_without_injury>3,119</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>903</sexual_offences>
        <robbery>964</robbery>
        <theft_offences total="54,647">
          <burglary total="16,661">
            <domestic>8,206</domestic>
            <non_domestic>8,455</non_domestic>
          </burglary>
          <vehicle_offences>12,439</vehicle_offences>
          <theft_from_the_person>1,805</theft_from_the_person>
          <bicycle_theft>1,448</bicycle_theft>
          <shoplifting>9,680</shoplifting>
          <other>12,614</other>
        </theft_offences>
        <criminal_damage_and_arson>16,644</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="8614"/>
        <drug_offences>4,401</drug_offences>
        <posession_of_weapons_offences>505</posession_of_weapons_offences>
        <public_order_offences>2,029</public_order_offences>
        <miscellaneous>894</miscellaneous>
        <fraud>1,679</fraud>
      </other_crimes_against_society>
    </area>
    <area id="West Yorkshire">
      <name>West Yorkshire</name>
      <total_recorded_crime>
        <including_fraud>163,746</including_fraud>
        <excluding_fraud>159,879</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="21,480">
          <homicide>15</homicide>
          <violence_with_injury>11,737</violence_with_injury>
          <violence_without_injury>9,728</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>2,684</sexual_offences>
        <robbery>1,974</robbery>
        <theft_offences total="93,721">
          <burglary total="26,608">
            <domestic>12,969</domestic>
            <non_domestic>13,639</non_domestic>
          </burglary>
          <vehicle_offences>21,577</vehicle_offences>
          <theft_from_the_person>4,993</theft_from_the_person>
          <bicycle_theft>2,109</bicycle_theft>
          <shoplifting>14,052</shoplifting>
          <other>24,382</other>
        </theft_offences>
        <criminal_damage_and_arson>25,654</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="16027"/>
        <drug_offences>6,798</drug_offences>
        <posession_of_weapons_offences>689</posession_of_weapons_offences>
        <public_order_offences>4,673</public_order_offences>
        <miscellaneous>2,206</miscellaneous>
        <fraud>3,867</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="East Midlands Region">
    <name>East Midlands Region</name>
    <area id="Derbyshire">
      <name>Derbyshire</name>
      <total_recorded_crime>
        <including_fraud>51,749</including_fraud>
        <excluding_fraud>50,970</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="9,529">
          <homicide>3</homicide>
          <violence_with_injury>5,220</violence_with_injury>
          <violence_without_injury>4,306</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>840</sexual_offences>
        <robbery>540</robbery>
        <theft_offences total="26,478">
          <burglary total="7,279">
            <domestic>2,868</domestic>
            <non_domestic>4,411</non_domestic>
          </burglary>
          <vehicle_offences>5,420</vehicle_offences>
          <theft_from_the_person>673</theft_from_the_person>
          <bicycle_theft>1,199</bicycle_theft>
          <shoplifting>5,090</shoplifting>
          <other>6,817</other>
        </theft_offences>
        <criminal_damage_and_arson>8,855</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4890"/>
        <drug_offences>2,651</drug_offences>
        <posession_of_weapons_offences>277</posession_of_weapons_offences>
        <public_order_offences>1,183</public_order_offences>
        <miscellaneous>617</miscellaneous>
        <fraud>779</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Leicestershire">
      <name>Leicestershire</name>
      <total_recorded_crime>
        <including_fraud>58,472</including_fraud>
        <excluding_fraud>57,352</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="10,157">
          <homicide>10</homicide>
          <violence_with_injury>4,442</violence_with_injury>
          <violence_without_injury>5,705</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,024</sexual_offences>
        <robbery>705</robbery>
        <theft_offences total="30,428">
          <burglary total="7,161">
            <domestic>3,743</domestic>
            <non_domestic>3,418</non_domestic>
          </burglary>
          <vehicle_offences>6,516</vehicle_offences>
          <theft_from_the_person>1,388</theft_from_the_person>
          <bicycle_theft>2,167</bicycle_theft>
          <shoplifting>5,541</shoplifting>
          <other>7,655</other>
        </theft_offences>
        <criminal_damage_and_arson>9,430</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="5982"/>
        <drug_offences>2,223</drug_offences>
        <posession_of_weapons_offences>297</posession_of_weapons_offences>
        <public_order_offences>2,342</public_order_offences>
        <miscellaneous>746</miscellaneous>
        <fraud>1,120</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Lincolnshire">
      <name>Lincolnshire</name>
      <total_recorded_crime>
        <including_fraud>37,023</including_fraud>
        <excluding_fraud>36,527</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="5,620">
          <homicide>6</homicide>
          <violence_with_injury>2,999</violence_with_injury>
          <violence_without_injury>2,615</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>579</sexual_offences>
        <robbery>172</robbery>
        <theft_offences total="20,428">
          <burglary total="5,386">
            <domestic>1,932</domestic>
            <non_domestic>3,454</non_domestic>
          </burglary>
          <vehicle_offences>3,316</vehicle_offences>
          <theft_from_the_person>400</theft_from_the_person>
          <bicycle_theft>1,466</bicycle_theft>
          <shoplifting>4,645</shoplifting>
          <other>5,215</other>
        </theft_offences>
        <criminal_damage_and_arson>6,026</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3644"/>
        <drug_offences>1,541</drug_offences>
        <posession_of_weapons_offences>250</posession_of_weapons_offences>
        <public_order_offences>1,357</public_order_offences>
        <miscellaneous>554</miscellaneous>
        <fraud>496</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Northamptonshire">
      <name>Northamptonshire</name>
      <total_recorded_crime>
        <including_fraud>45,273</including_fraud>
        <excluding_fraud>44,330</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="7,882">
          <homicide>6</homicide>
          <violence_with_injury>4,001</violence_with_injury>
          <violence_without_injury>3,875</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>758</sexual_offences>
        <robbery>596</robbery>
        <theft_offences total="23,626">
          <burglary total="6,459">
            <domestic>3,144</domestic>
            <non_domestic>3,315</non_domestic>
          </burglary>
          <vehicle_offences>5,342</vehicle_offences>
          <theft_from_the_person>1,167</theft_from_the_person>
          <bicycle_theft>898</bicycle_theft>
          <shoplifting>4,468</shoplifting>
          <other>5,292</other>
        </theft_offences>
        <criminal_damage_and_arson>7,966</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3941"/>
        <drug_offences>1,798</drug_offences>
        <posession_of_weapons_offences>247</posession_of_weapons_offences>
        <public_order_offences>953</public_order_offences>
        <miscellaneous>504</miscellaneous>
        <fraud>943</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Nottinghamshire">
      <name>Nottinghamshire</name>
      <total_recorded_crime>
        <including_fraud>68,777</including_fraud>
        <excluding_fraud>67,950</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="13,217">
          <homicide>14</homicide>
          <violence_with_injury>7,106</violence_with_injury>
          <violence_without_injury>6,097</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,020</sexual_offences>
        <robbery>1,005</robbery>
        <theft_offences total="35,186">
          <burglary total="8,606">
            <domestic>4,353</domestic>
            <non_domestic>4,253</non_domestic>
          </burglary>
          <vehicle_offences>6,893</vehicle_offences>
          <theft_from_the_person>1,980</theft_from_the_person>
          <bicycle_theft>1,955</bicycle_theft>
          <shoplifting>7,138</shoplifting>
          <other>8,614</other>
        </theft_offences>
        <criminal_damage_and_arson>10,662</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="6906"/>
        <drug_offences>3,814</drug_offences>
        <posession_of_weapons_offences>472</posession_of_weapons_offences>
        <public_order_offences>1,793</public_order_offences>
        <miscellaneous>781</miscellaneous>
        <fraud>827</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="West Midlands Region">
    <name>West Midlands Region</name>
    <area id="Staffordshire">
      <name>Staffordshire</name>
      <total_recorded_crime>
        <including_fraud>58,897</including_fraud>
        <excluding_fraud>57,493</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="13,299">
          <homicide>4</homicide>
          <violence_with_injury>6,982</violence_with_injury>
          <violence_without_injury>6,313</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,171</sexual_offences>
        <robbery>485</robbery>
        <theft_offences total="25,557">
          <burglary total="6,634">
            <domestic>2,712</domestic>
            <non_domestic>3,922</non_domestic>
          </burglary>
          <vehicle_offences>4,741</vehicle_offences>
          <theft_from_the_person>486</theft_from_the_person>
          <bicycle_theft>894</bicycle_theft>
          <shoplifting>5,148</shoplifting>
          <other>7,654</other>
        </theft_offences>
        <criminal_damage_and_arson>10,410</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="7098"/>
        <drug_offences>3,549</drug_offences>
        <posession_of_weapons_offences>320</posession_of_weapons_offences>
        <public_order_offences>1,825</public_order_offences>
        <miscellaneous>877</miscellaneous>
        <fraud>1,404</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Warwickshire">
      <name>Warwickshire</name>
      <total_recorded_crime>
        <including_fraud>29,223</including_fraud>
        <excluding_fraud>28,751</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="4,178">
          <homicide>1</homicide>
          <violence_with_injury>2,600</violence_with_injury>
          <violence_without_injury>1,577</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>481</sexual_offences>
        <robbery>253</robbery>
        <theft_offences total="16,745">
          <burglary total="4,290">
            <domestic>1,855</domestic>
            <non_domestic>2,435</non_domestic>
          </burglary>
          <vehicle_offences>4,185</vehicle_offences>
          <theft_from_the_person>290</theft_from_the_person>
          <bicycle_theft>722</bicycle_theft>
          <shoplifting>2,211</shoplifting>
          <other>5,047</other>
        </theft_offences>
        <criminal_damage_and_arson>4,500</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="2749"/>
        <drug_offences>1,427</drug_offences>
        <posession_of_weapons_offences>126</posession_of_weapons_offences>
        <public_order_offences>724</public_order_offences>
        <miscellaneous>317</miscellaneous>
        <fraud>472</fraud>
      </other_crimes_against_society>
    </area>
    <area id="West Mercia">
      <name>West Mercia</name>
      <total_recorded_crime>
        <including_fraud>59,209</including_fraud>
        <excluding_fraud>58,239</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="11,262">
          <homicide>16</homicide>
          <violence_with_injury>6,336</violence_with_injury>
          <violence_without_injury>4,910</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,228</sexual_offences>
        <robbery>379</robbery>
        <theft_offences total="29,572">
          <burglary total="7,536">
            <domestic>2,588</domestic>
            <non_domestic>4,948</non_domestic>
          </burglary>
          <vehicle_offences>5,908</vehicle_offences>
          <theft_from_the_person>568</theft_from_the_person>
          <bicycle_theft>1,336</bicycle_theft>
          <shoplifting>5,895</shoplifting>
          <other>8,329</other>
        </theft_offences>
        <criminal_damage_and_arson>9,413</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="6485"/>
        <drug_offences>3,140</drug_offences>
        <posession_of_weapons_offences>335</posession_of_weapons_offences>
        <public_order_offences>2,040</public_order_offences>
        <miscellaneous>870</miscellaneous>
        <fraud>970</fraud>
      </other_crimes_against_society>
    </area>
    <area id="West Midlands">
      <name>West Midlands</name>
      <total_recorded_crime>
        <including_fraud>171,311</including_fraud>
        <excluding_fraud>166,870</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="30,387">
          <homicide>42</homicide>
          <violence_with_injury>18,087</violence_with_injury>
          <violence_without_injury>12,258</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>2,786</sexual_offences>
        <robbery>5,364</robbery>
        <theft_offences total="86,242">
          <burglary total="24,249">
            <domestic>13,365</domestic>
            <non_domestic>10,884</non_domestic>
          </burglary>
          <vehicle_offences>23,093</vehicle_offences>
          <theft_from_the_person>3,689</theft_from_the_person>
          <bicycle_theft>3,026</bicycle_theft>
          <shoplifting>14,703</shoplifting>
          <other>17,482</other>
        </theft_offences>
        <criminal_damage_and_arson>24,885</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="19437"/>
        <drug_offences>8,132</drug_offences>
        <posession_of_weapons_offences>1,222</posession_of_weapons_offences>
        <public_order_offences>5,642</public_order_offences>
        <miscellaneous>2,210</miscellaneous>
        <fraud>4,441</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="East of England Region">
    <name>East of England Region</name>
    <area id="Bedfordshire">
      <name>Bedfordshire</name>
      <total_recorded_crime>
        <including_fraud>35,453</including_fraud>
        <excluding_fraud>34,937</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="5,977">
          <homicide>7</homicide>
          <violence_with_injury>3,103</violence_with_injury>
          <violence_without_injury>2,867</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>481</sexual_offences>
        <robbery>615</robbery>
        <theft_offences total="18,693">
          <burglary total="4,960">
            <domestic>2,885</domestic>
            <non_domestic>2,075</non_domestic>
          </burglary>
          <vehicle_offences>4,510</vehicle_offences>
          <theft_from_the_person>561</theft_from_the_person>
          <bicycle_theft>983</bicycle_theft>
          <shoplifting>3,198</shoplifting>
          <other>4,481</other>
        </theft_offences>
        <criminal_damage_and_arson>5,746</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3450"/>
        <drug_offences>1,542</drug_offences>
        <posession_of_weapons_offences>264</posession_of_weapons_offences>
        <public_order_offences>1,128</public_order_offences>
        <miscellaneous>491</miscellaneous>
        <fraud>516</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Cambridgeshire">
      <name>Cambridgeshire</name>
      <total_recorded_crime>
        <including_fraud>45,091</including_fraud>
        <excluding_fraud>43,995</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,170">
          <homicide>9</homicide>
          <violence_with_injury>2,873</violence_with_injury>
          <violence_without_injury>3,288</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>672</sexual_offences>
        <robbery>332</robbery>
        <theft_offences total="25,537">
          <burglary total="5,501">
            <domestic>2,573</domestic>
            <non_domestic>2,928</non_domestic>
          </burglary>
          <vehicle_offences>4,483</vehicle_offences>
          <theft_from_the_person>985</theft_from_the_person>
          <bicycle_theft>3,611</bicycle_theft>
          <shoplifting>4,442</shoplifting>
          <other>6,515</other>
        </theft_offences>
        <criminal_damage_and_arson>6,406</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="5468"/>
        <drug_offences>2,874</drug_offences>
        <posession_of_weapons_offences>217</posession_of_weapons_offences>
        <public_order_offences>1,281</public_order_offences>
        <miscellaneous>506</miscellaneous>
        <fraud>1,096</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Essex">
      <name>Essex</name>
      <total_recorded_crime>
        <including_fraud>99,741</including_fraud>
        <excluding_fraud>97,916</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="17,915">
          <homicide>20</homicide>
          <violence_with_injury>8,829</violence_with_injury>
          <violence_without_injury>9,066</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,527</sexual_offences>
        <robbery>1,172</robbery>
        <theft_offences total="53,708">
          <burglary total="14,367">
            <domestic>7,874</domestic>
            <non_domestic>6,493</non_domestic>
          </burglary>
          <vehicle_offences>12,856</vehicle_offences>
          <theft_from_the_person>1,699</theft_from_the_person>
          <bicycle_theft>2,248</bicycle_theft>
          <shoplifting>9,274</shoplifting>
          <other>13,264</other>
        </theft_offences>
        <criminal_damage_and_arson>14,309</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="9982"/>
        <drug_offences>4,122</drug_offences>
        <posession_of_weapons_offences>832</posession_of_weapons_offences>
        <public_order_offences>3,203</public_order_offences>
        <miscellaneous>1,128</miscellaneous>
        <fraud>1,825</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Hertfordshire">
      <name>Hertfordshire</name>
      <total_recorded_crime>
        <including_fraud>51,868</including_fraud>
        <excluding_fraud>50,542</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="7,822">
          <homicide>10</homicide>
          <violence_with_injury>4,080</violence_with_injury>
          <violence_without_injury>3,732</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>691</sexual_offences>
        <robbery>439</robbery>
        <theft_offences total="25,608">
          <burglary total="5,648">
            <domestic>2,900</domestic>
            <non_domestic>2,748</non_domestic>
          </burglary>
          <vehicle_offences>5,537</vehicle_offences>
          <theft_from_the_person>1,336</theft_from_the_person>
          <bicycle_theft>1,174</bicycle_theft>
          <shoplifting>5,409</shoplifting>
          <other>6,504</other>
        </theft_offences>
        <criminal_damage_and_arson>8,054</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="8466"/>
        <drug_offences>4,785</drug_offences>
        <posession_of_weapons_offences>293</posession_of_weapons_offences>
        <public_order_offences>2,062</public_order_offences>
        <miscellaneous>788</miscellaneous>
        <fraud>1,326</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Norfolk">
      <name>Norfolk</name>
      <total_recorded_crime>
        <including_fraud>37,996</including_fraud>
        <excluding_fraud>37,493</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="8,034">
          <homicide>5</homicide>
          <violence_with_injury>3,875</violence_with_injury>
          <violence_without_injury>4,154</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>776</sexual_offences>
        <robbery>164</robbery>
        <theft_offences total="17,058">
          <burglary total="3,779">
            <domestic>1,383</domestic>
            <non_domestic>2,396</non_domestic>
          </burglary>
          <vehicle_offences>2,774</vehicle_offences>
          <theft_from_the_person>376</theft_from_the_person>
          <bicycle_theft>1,241</bicycle_theft>
          <shoplifting>3,852</shoplifting>
          <other>5,036</other>
        </theft_offences>
        <criminal_damage_and_arson>6,988</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4611"/>
        <drug_offences>2,413</drug_offences>
        <posession_of_weapons_offences>212</posession_of_weapons_offences>
        <public_order_offences>1,483</public_order_offences>
        <miscellaneous>365</miscellaneous>
        <fraud>503</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Suffolk">
      <name>Suffolk</name>
      <total_recorded_crime>
        <including_fraud>39,147</including_fraud>
        <excluding_fraud>38,423</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="7,109">
          <homicide>8</homicide>
          <violence_with_injury>3,683</violence_with_injury>
          <violence_without_injury>3,418</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>708</sexual_offences>
        <robbery>226</robbery>
        <theft_offences total="18,726">
          <burglary total="4,776">
            <domestic>1,872</domestic>
            <non_domestic>2,904</non_domestic>
          </burglary>
          <vehicle_offences>3,692</vehicle_offences>
          <theft_from_the_person>423</theft_from_the_person>
          <bicycle_theft>1,159</bicycle_theft>
          <shoplifting>3,721</shoplifting>
          <other>4,955</other>
        </theft_offences>
        <criminal_damage_and_arson>6,844</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4863"/>
        <drug_offences>1,961</drug_offences>
        <posession_of_weapons_offences>233</posession_of_weapons_offences>
        <public_order_offences>1,945</public_order_offences>
        <miscellaneous>671</miscellaneous>
        <fraud>724</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="London Region">
    <name>London Region</name>
    <area id="London, City of">
      <name>London, City of</name>
      <total_recorded_crime>
        <including_fraud>5,552</including_fraud>
        <excluding_fraud>5,522</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="534">
          <homicide>0</homicide>
          <violence_with_injury>298</violence_with_injury>
          <violence_without_injury>236</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>50</sexual_offences>
        <robbery>48</robbery>
        <theft_offences total="3,761">
          <burglary total="341">
            <domestic>34</domestic>
            <non_domestic>307</non_domestic>
          </burglary>
          <vehicle_offences>188</vehicle_offences>
          <theft_from_the_person>353</theft_from_the_person>
          <bicycle_theft>326</bicycle_theft>
          <shoplifting>584</shoplifting>
          <other>1,969</other>
        </theft_offences>
        <criminal_damage_and_arson>237</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="741"/>
        <drug_offences>488</drug_offences>
        <posession_of_weapons_offences>22</posession_of_weapons_offences>
        <public_order_offences>201</public_order_offences>
        <miscellaneous>181</miscellaneous>
        <fraud>30</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Metropolitan Police">
      <name>Metropolitan Police</name>
      <total_recorded_crime>
        <including_fraud>744,633</including_fraud>
        <excluding_fraud>717,877</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="123,188">
          <homicide>99</homicide>
          <violence_with_injury>56,496</violence_with_injury>
          <violence_without_injury>66,593</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>9,905</sexual_offences>
        <robbery>32,714</robbery>
        <theft_offences total="406,098">
          <burglary total="90,742">
            <domestic>59,111</domestic>
            <non_domestic>31,631</non_domestic>
          </burglary>
          <vehicle_offences>92,257</vehicle_offences>
          <theft_from_the_person>48,904</theft_from_the_person>
          <bicycle_theft>20,160</bicycle_theft>
          <shoplifting>36,918</shoplifting>
          <other>117,117</other>
        </theft_offences>
        <criminal_damage_and_arson>57,307</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="107711"/>
        <drug_offences>50,775</drug_offences>
        <posession_of_weapons_offences>3,751</posession_of_weapons_offences>
        <public_order_offences>26,429</public_order_offences>
        <miscellaneous>7,710</miscellaneous>
        <fraud>26,756</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="South East Region">
    <name>South East Region</name>
    <area id="Hampshire">
      <name>Hampshire</name>
      <total_recorded_crime>
        <including_fraud>106,100</including_fraud>
        <excluding_fraud>103,977</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="21,314">
          <homicide>11</homicide>
          <violence_with_injury>10,879</violence_with_injury>
          <violence_without_injury>10,424</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,740</sexual_offences>
        <robbery>694</robbery>
        <theft_offences total="49,495">
          <burglary total="10,811">
            <domestic>3,753</domestic>
            <non_domestic>7,058</non_domestic>
          </burglary>
          <vehicle_offences>8,133</vehicle_offences>
          <theft_from_the_person>1,769</theft_from_the_person>
          <bicycle_theft>3,794</bicycle_theft>
          <shoplifting>11,017</shoplifting>
          <other>13,971</other>
        </theft_offences>
        <criminal_damage_and_arson>18,004</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="13646"/>
        <drug_offences>6,582</drug_offences>
        <posession_of_weapons_offences>524</posession_of_weapons_offences>
        <public_order_offences>4,417</public_order_offences>
        <miscellaneous>1,207</miscellaneous>
        <fraud>2,123</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Kent">
      <name>Kent</name>
      <total_recorded_crime>
        <including_fraud>100,924</including_fraud>
        <excluding_fraud>99,429</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="19,692">
          <homicide>10</homicide>
          <violence_with_injury>10,393</violence_with_injury>
          <violence_without_injury>9,289</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,588</sexual_offences>
        <robbery>951</robbery>
        <theft_offences total="51,287">
          <burglary total="13,977">
            <domestic>6,557</domestic>
            <non_domestic>7,420</non_domestic>
          </burglary>
          <vehicle_offences>10,535</vehicle_offences>
          <theft_from_the_person>848</theft_from_the_person>
          <bicycle_theft>1,651</bicycle_theft>
          <shoplifting>10,441</shoplifting>
          <other>13,835</other>
        </theft_offences>
        <criminal_damage_and_arson>17,803</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="8389"/>
        <drug_offences>4,167</drug_offences>
        <posession_of_weapons_offences>428</posession_of_weapons_offences>
        <public_order_offences>2,299</public_order_offences>
        <miscellaneous>1,214</miscellaneous>
        <fraud>1,495</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Surrey">
      <name>Surrey</name>
      <total_recorded_crime>
        <including_fraud>52,334</including_fraud>
        <excluding_fraud>50,779</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="8,644">
          <homicide>4</homicide>
          <violence_with_injury>2,977</violence_with_injury>
          <violence_without_injury>5,663</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>587</sexual_offences>
        <robbery>239</robbery>
        <theft_offences total="25,520">
          <burglary total="7,481">
            <domestic>3,397</domestic>
            <non_domestic>4,084</non_domestic>
          </burglary>
          <vehicle_offences>5,130</vehicle_offences>
          <theft_from_the_person>395</theft_from_the_person>
          <bicycle_theft>1,344</bicycle_theft>
          <shoplifting>4,033</shoplifting>
          <other>7,137</other>
        </theft_offences>
        <criminal_damage_and_arson>9,109</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="7304"/>
        <drug_offences>3,706</drug_offences>
        <posession_of_weapons_offences>270</posession_of_weapons_offences>
        <public_order_offences>1,773</public_order_offences>
        <miscellaneous>931</miscellaneous>
        <fraud>1,555</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Sussex">
      <name>Sussex</name>
      <total_recorded_crime>
        <including_fraud>87,978</including_fraud>
        <excluding_fraud>86,118</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="14,870">
          <homicide>12</homicide>
          <violence_with_injury>6,985</violence_with_injury>
          <violence_without_injury>7,873</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,593</sexual_offences>
        <robbery>648</robbery>
        <theft_offences total="46,180">
          <burglary total="9,607">
            <domestic>3,846</domestic>
            <non_domestic>5,761</non_domestic>
          </burglary>
          <vehicle_offences>8,231</vehicle_offences>
          <theft_from_the_person>3,199</theft_from_the_person>
          <bicycle_theft>2,669</bicycle_theft>
          <shoplifting>8,351</shoplifting>
          <other>14,123</other>
        </theft_offences>
        <criminal_damage_and_arson>14,015</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="9474"/>
        <drug_offences>4,467</drug_offences>
        <posession_of_weapons_offences>519</posession_of_weapons_offences>
        <public_order_offences>2,628</public_order_offences>
        <miscellaneous>1,198</miscellaneous>
        <fraud>1,860</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Thames Valley">
      <name>Thames Valley</name>
      <total_recorded_crime>
        <including_fraud>133,260</including_fraud>
        <excluding_fraud>129,025</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="19,574">
          <homicide>20</homicide>
          <violence_with_injury>8,425</violence_with_injury>
          <violence_without_injury>11,129</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>2,159</sexual_offences>
        <robbery>1,184</robbery>
        <theft_offences total="73,547">
          <burglary total="15,909">
            <domestic>6,805</domestic>
            <non_domestic>9,104</non_domestic>
          </burglary>
          <vehicle_offences>14,856</vehicle_offences>
          <theft_from_the_person>3,014</theft_from_the_person>
          <bicycle_theft>5,651</bicycle_theft>
          <shoplifting>13,905</shoplifting>
          <other>20,212</other>
        </theft_offences>
        <criminal_damage_and_arson>17,941</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="17209"/>
        <drug_offences>6,953</drug_offences>
        <posession_of_weapons_offences>731</posession_of_weapons_offences>
        <public_order_offences>5,290</public_order_offences>
        <miscellaneous>1,646</miscellaneous>
        <fraud>4,235</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="South West Region">
    <name>South West Region</name>
    <area id="Avon and Somerset">
      <name>Avon and Somerset</name>
      <total_recorded_crime>
        <including_fraud>97,049</including_fraud>
        <excluding_fraud>95,528</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="15,895">
          <homicide>13</homicide>
          <violence_with_injury>8,124</violence_with_injury>
          <violence_without_injury>7,758</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,534</sexual_offences>
        <robbery>767</robbery>
        <theft_offences total="48,160">
          <burglary total="11,231">
            <domestic>4,889</domestic>
            <non_domestic>6,342</non_domestic>
          </burglary>
          <vehicle_offences>9,239</vehicle_offences>
          <theft_from_the_person>1,626</theft_from_the_person>
          <bicycle_theft>2,812</bicycle_theft>
          <shoplifting>10,636</shoplifting>
          <other>12,616</other>
        </theft_offences>
        <criminal_damage_and_arson>15,725</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="13710"/>
        <drug_offences>6,726</drug_offences>
        <posession_of_weapons_offences>499</posession_of_weapons_offences>
        <public_order_offences>4,964</public_order_offences>
        <miscellaneous>1,258</miscellaneous>
        <fraud>1,521</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Devon and Cornwall">
      <name>Devon and Cornwall</name>
      <total_recorded_crime>
        <including_fraud>84,866</including_fraud>
        <excluding_fraud>83,544</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="19,670">
          <homicide>10</homicide>
          <violence_with_injury>10,680</violence_with_injury>
          <violence_without_injury>8,980</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>2,009</sexual_offences>
        <robbery>378</robbery>
        <theft_offences total="35,192">
          <burglary total="8,030">
            <domestic>3,334</domestic>
            <non_domestic>4,696</non_domestic>
          </burglary>
          <vehicle_offences>6,139</vehicle_offences>
          <theft_from_the_person>1,128</theft_from_the_person>
          <bicycle_theft>1,286</bicycle_theft>
          <shoplifting>7,311</shoplifting>
          <other>11,298</other>
        </theft_offences>
        <criminal_damage_and_arson>15,025</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="11637"/>
        <drug_offences>4,509</drug_offences>
        <posession_of_weapons_offences>416</posession_of_weapons_offences>
        <public_order_offences>5,390</public_order_offences>
        <miscellaneous>955</miscellaneous>
        <fraud>1,322</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Dorset">
      <name>Dorset</name>
      <total_recorded_crime>
        <including_fraud>39,402</including_fraud>
        <excluding_fraud>38,963</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,050">
          <homicide>5</homicide>
          <violence_with_injury>3,574</violence_with_injury>
          <violence_without_injury>2,471</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>586</sexual_offences>
        <robbery>198</robbery>
        <theft_offences total="22,027">
          <burglary total="5,093">
            <domestic>1,833</domestic>
            <non_domestic>3,260</non_domestic>
          </burglary>
          <vehicle_offences>4,960</vehicle_offences>
          <theft_from_the_person>633</theft_from_the_person>
          <bicycle_theft>1,735</bicycle_theft>
          <shoplifting>3,722</shoplifting>
          <other>5,884</other>
        </theft_offences>
        <criminal_damage_and_arson>7,111</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3080"/>
        <drug_offences>1,497</drug_offences>
        <posession_of_weapons_offences>165</posession_of_weapons_offences>
        <public_order_offences>979</public_order_offences>
        <miscellaneous>350</miscellaneous>
        <fraud>439</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Gloucestershire">
      <name>Gloucestershire</name>
      <total_recorded_crime>
        <including_fraud>30,250</including_fraud>
        <excluding_fraud>29,595</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="4,360">
          <homicide>1</homicide>
          <violence_with_injury>2,599</violence_with_injury>
          <violence_without_injury>1,760</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>522</sexual_offences>
        <robbery>231</robbery>
        <theft_offences total="16,754">
          <burglary total="4,701">
            <domestic>2,192</domestic>
            <non_domestic>2,509</non_domestic>
          </burglary>
          <vehicle_offences>3,061</vehicle_offences>
          <theft_from_the_person>366</theft_from_the_person>
          <bicycle_theft>1,102</bicycle_theft>
          <shoplifting>3,261</shoplifting>
          <other>4,263</other>
        </theft_offences>
        <criminal_damage_and_arson>4,854</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3148"/>
        <drug_offences>1,646</drug_offences>
        <posession_of_weapons_offences>134</posession_of_weapons_offences>
        <public_order_offences>713</public_order_offences>
        <miscellaneous>381</miscellaneous>
        <fraud>655</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Wiltshire">
      <name>Wiltshire</name>
      <total_recorded_crime>
        <including_fraud>33,363</including_fraud>
        <excluding_fraud>32,587</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,144">
          <homicide>9</homicide>
          <violence_with_injury>3,421</violence_with_injury>
          <violence_without_injury>2,714</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>644</sexual_offences>
        <robbery>129</robbery>
        <theft_offences total="16,776">
          <burglary total="4,331">
            <domestic>1,265</domestic>
            <non_domestic>3,066</non_domestic>
          </burglary>
          <vehicle_offences>3,348</vehicle_offences>
          <theft_from_the_person>402</theft_from_the_person>
          <bicycle_theft>755</bicycle_theft>
          <shoplifting>3,208</shoplifting>
          <other>4,732</other>
        </theft_offences>
        <criminal_damage_and_arson>5,994</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3428"/>
        <drug_offences>1,624</drug_offences>
        <posession_of_weapons_offences>136</posession_of_weapons_offences>
        <public_order_offences>892</public_order_offences>
        <miscellaneous>248</miscellaneous>
        <fraud>776</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="WALES">
    <name>WALES</name>
    <area id="ENGLAND">
      <name>ENGLAND</name>
      <total_recorded_crime>
        <including_fraud>3,344,716</including_fraud>
        <excluding_fraud>3,267,603</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="560,890">
          <homicide>498</homicide>
          <violence_with_injury>289,344</violence_with_injury>
          <violence_without_injury>271,048</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>52,235</sexual_offences>
        <robbery>61,126</robbery>
        <theft_offences total="1,739,191">
          <burglary total="434,619">
            <domestic>216,111</domestic>
            <non_domestic>218,508</non_domestic>
          </burglary>
          <vehicle_offences>364,843</vehicle_offences>
          <theft_from_the_person>98,134</theft_from_the_person>
          <bicycle_theft>88,504</bicycle_theft>
          <shoplifting>289,493</shoplifting>
          <other>463,598</other>
        </theft_offences>
        <criminal_damage_and_arson>489,316</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="402139"/>
        <drug_offences>190,249</drug_offences>
        <posession_of_weapons_offences>18,602</posession_of_weapons_offences>
        <public_order_offences>116,175</public_order_offences>
        <miscellaneous>39,819</miscellaneous>
        <fraud>77,113</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Dyfed-Powys">
      <name>Dyfed-Powys</name>
      <total_recorded_crime>
        <including_fraud>18,903</including_fraud>
        <excluding_fraud>18,532</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="3,401">
          <homicide>5</homicide>
          <violence_with_injury>2,068</violence_with_injury>
          <violence_without_injury>1,328</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>376</sexual_offences>
        <robbery>24</robbery>
        <theft_offences total="6,376">
          <burglary total="1,349">
            <domestic>444</domestic>
            <non_domestic>905</non_domestic>
          </burglary>
          <vehicle_offences>996</vehicle_offences>
          <theft_from_the_person>60</theft_from_the_person>
          <bicycle_theft>174</bicycle_theft>
          <shoplifting>1,573</shoplifting>
          <other>2,224</other>
        </theft_offences>
        <criminal_damage_and_arson>3,326</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="5200"/>
        <drug_offences>3,464</drug_offences>
        <posession_of_weapons_offences>146</posession_of_weapons_offences>
        <public_order_offences>1,219</public_order_offences>
        <miscellaneous>200</miscellaneous>
        <fraud>371</fraud>
      </other_crimes_against_society>
    </area>
    <area id="Gwent">
      <name>Gwent</name>
      <total_recorded_crime>
        <including_fraud>34,595</including_fraud>
        <excluding_fraud>34,328</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,301">
          <homicide>5</homicide>
          <violence_with_injury>3,480</violence_with_injury>
          <violence_without_injury>2,816</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>504</sexual_offences>
        <robbery>178</robbery>
        <theft_offences total="16,711">
          <burglary total="4,646">
            <domestic>1,775</domestic>
            <non_domestic>2,871</non_domestic>
          </burglary>
          <vehicle_offences>3,654</vehicle_offences>
          <theft_from_the_person>155</theft_from_the_person>
          <bicycle_theft>440</bicycle_theft>
          <shoplifting>3,310</shoplifting>
          <other>4,506</other>
        </theft_offences>
        <criminal_damage_and_arson>6,374</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="4109"/>
        <drug_offences>2,319</drug_offences>
        <posession_of_weapons_offences>176</posession_of_weapons_offences>
        <public_order_offences>1,347</public_order_offences>
        <miscellaneous>418</miscellaneous>
        <fraud>267</fraud>
      </other_crimes_against_society>
    </area>
    <area id="North Wales">
      <name>North Wales</name>
      <total_recorded_crime>
        <including_fraud>36,584</including_fraud>
        <excluding_fraud>36,232</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="7,924">
          <homicide>11</homicide>
          <violence_with_injury>4,076</violence_with_injury>
          <violence_without_injury>3,837</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>858</sexual_offences>
        <robbery>135</robbery>
        <theft_offences total="16,033">
          <burglary total="4,635">
            <domestic>1,614</domestic>
            <non_domestic>3,021</non_domestic>
          </burglary>
          <vehicle_offences>2,496</vehicle_offences>
          <theft_from_the_person>197</theft_from_the_person>
          <bicycle_theft>597</bicycle_theft>
          <shoplifting>3,566</shoplifting>
          <other>4,542</other>
        </theft_offences>
        <criminal_damage_and_arson>7,229</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="3966"/>
        <drug_offences>1,717</drug_offences>
        <posession_of_weapons_offences>170</posession_of_weapons_offences>
        <public_order_offences>1,727</public_order_offences>
        <miscellaneous>439</miscellaneous>
        <fraud>352</fraud>
      </other_crimes_against_society>
    </area>
    <area id="South Wales">
      <name>South Wales</name>
      <total_recorded_crime>
        <including_fraud>83,532</including_fraud>
        <excluding_fraud>82,089</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="13,606">
          <homicide>10</homicide>
          <violence_with_injury>8,563</violence_with_injury>
          <violence_without_injury>5,033</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>1,198</sexual_offences>
        <robbery>396</robbery>
        <theft_offences total="42,059">
          <burglary total="9,130">
            <domestic>3,956</domestic>
            <non_domestic>5,174</non_domestic>
          </burglary>
          <vehicle_offences>10,208</vehicle_offences>
          <theft_from_the_person>2,056</theft_from_the_person>
          <bicycle_theft>1,751</bicycle_theft>
          <shoplifting>7,857</shoplifting>
          <other>11,057</other>
        </theft_offences>
        <criminal_damage_and_arson>14,271</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="11058"/>
        <drug_offences>5,263</drug_offences>
        <posession_of_weapons_offences>463</posession_of_weapons_offences>
        <public_order_offences>3,889</public_order_offences>
        <miscellaneous>944</miscellaneous>
        <fraud>1,443</fraud>
      </other_crimes_against_society>
    </area>
  </region>
  <region id="ENGLAND AND WALES">
    <name>ENGLAND AND WALES</name>
    <area id="British Transport Police">
      <name>British Transport Police</name>
      <total_recorded_crime>
        <including_fraud>51,970</including_fraud>
        <excluding_fraud>51,570</excluding_fraud>
      </total_recorded_crime>
      <victim_based>
        <violence_against_the_person total="6,151">
          <homicide>3</homicide>
          <violence_with_injury>2,093</violence_with_injury>
          <violence_without_injury>4,055</violence_without_injury>
        </violence_against_the_person>
        <sexual_offences>641</sexual_offences>
        <robbery>505</robbery>
        <theft_offences total="28,102">
          <burglary total="529">
            <domestic>2</domestic>
            <non_domestic>527</non_domestic>
          </burglary>
          <vehicle_offences>1,526</vehicle_offences>
          <theft_from_the_person>9,116</theft_from_the_person>
          <bicycle_theft>5,093</bicycle_theft>
          <shoplifting>1,853</shoplifting>
          <other>9,985</other>
        </theft_offences>
        <criminal_damage_and_arson>4,761</criminal_damage_and_arson>
      </victim_based>
      <other_crimes_against_society>
        <other_crimes_against_society total="10898"/>
        <drug_offences>3,614</drug_offences>
        <posession_of_weapons_offences>363</posession_of_weapons_offences>
        <public_order_offences>6,521</public_order_offences>
        <miscellaneous>912</miscellaneous>
        <fraud>400</fraud>
      </other_crimes_against_society>
    </area>
  </region>
</crimes>




Is This A Good Question/Topic? 0
  • +

Replies To: http get XML to json

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,607
  • Joined: 12-June 08

Re: http get XML to json

Posted 08 January 2014 - 10:41 AM

Quote

Any help would be greatly appreciated.

Would you be more specific on what you need help on.
Was This Post Helpful? 0
  • +
  • -

#3 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

Re: http get XML to json

Posted 08 January 2014 - 10:48 AM

I need help on achieving this:

xml:

<response timestamp="xxxxxxxxxx">
  <crimes year="6-2013">
   <region id="North East" total="138982" />
   <region id="North West" total="444423" />
   ...
   ...
   <national id="British Transport Police" total="51968" />
   <national id="Action Fraud" total="150389" />
   <england total="3344716" />
   <wales total="173614" />
 </crimes>
</response>



json:

{
  "response": {
  "timestamp": "xxxxxxxxxx",
    "crimes": {
      "year": "6-2013",
      "region": [
        { "id": "North East", "total": "138982" },
        { "id": "North West", "total": "444423" }
        ....
        ....
               ],
      "national": [
        { "id": "British Transport Police", "total": "51968" },
        { "id": "Action Fraud", "total": "150389" }
                  ],
      "england": { "total": "3344716" },
      "wales": { "total": "173614" },
    }
  }
}



I need to use php to generate this and need help on doing so.

When you type in this:
http://www.cems.uwe....imes/6-2013/xml
http://www.cems.uwe....mes/6-2013/json

It should return the code above making use of the xml file i included in my previous post.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,607
  • Joined: 12-June 08

Re: http get XML to json

Posted 08 January 2014 - 10:53 AM

Okay.. so.. you just want someone to generate the code for you? What have you tried?
Was This Post Helpful? 0
  • +
  • -

#5 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

Re: http get XML to json

Posted 08 January 2014 - 10:59 AM

This is what I have tried:

<?php
switch(uwe\atwd\uri::get('response'))
{
    // Build the XML response object
    case 'xml':
    default:
        header('Content-type: text/xml');
        $dom = new DOMDocument;
        $dom->formatOutput = true;

        $node = $dom->createElement('response');
        $node->setAttribute('timestamp', time());

        $response = $dom->appendChild($node);

        $node = $dom->createElement('crimes');
        $node->setAttribute('year', uwe\atwd\uri::get('year'));
        $crimes = $response->appendChild($node);

        foreach($regions as $key => $region)
        {
            if($key != 'wales')
            {
                if(!isset($england))
                {
                    $england = 0;
                }
                $england += $region->getTotalCrime(true);
            }

            if($key == 'btp' || $key == 'af')
            {
                $node = $dom->createElement('national');
            }
            else
            {
                $node = $dom->createElement('region');
            }
            $node->setAttribute('id', ucwords($region->name));
            $node->setAttribute('total', $region->getTotalCrime(true));
            $crimes->appendChild($node);
        }

        $node = $dom->createElement('england');
        $node->setAttribute('total', $england);
        $crimes->appendChild($node);

        $node = $dom->createElement('wales');
        $node->setAttribute('total', $regions['wales']->getTotalCrime(true));
        $crimes->appendChild($node);

        // Echo out the XML
        echo $dom->saveXML();
        break;

    // Build the JSON response object
    case 'json':
        header('Content-type: application/json');
        $json['response']['timestamp'] = time();
        $json['response']['crimes']['year'] = $_GET['year'];

        // Loop through the regions;
        foreach($regions as $key => $region)
        {
            if($key != 'wales')
            {
                if(!isset($england))
                {
                    $england = 0;
                }
                $england += $region->getTotalCrime(true);
            }

            if($key == 'btp' || $key == 'af')
            {
                $json['response']['crimes']['national'][] = array('id' => $region->name, 'total' => $region->getTotalCrime(true));
            }
            else
            {
                $json['response']['crimes']['region'][] = array('id' => $region->name, 'total' => $region->getTotalCrime(true));
            }
        }

        $json['response']['crimes']['england']['total'] = $england;
        $json['response']['crimes']['wales']['total'] = $regions['wales']->getTotalCrime(true);

        // Echo out the JSON
        echo json_encode($json);
        break;
}

?>


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,607
  • Joined: 12-June 08

Re: http get XML to json

Posted 08 January 2014 - 11:04 AM

Okay.. this isn't a duplicate of a previous topic, is it?

From what you have there can you explain what it is doing versus what it should be doing?
Was This Post Helpful? 0
  • +
  • -

#7 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

Re: http get XML to json

Posted 11 January 2014 - 09:47 AM

I have managed to get the json to work however the totals are not being added or displayed.

Here is my xml - www.cems.uwe.ac.uk/~c9-adams/atwd/crimes/output.xml

I want to add the numbers contained with the '<total_recorded_crime> tags.

so the output would be:

{
  "response": {
  "timestamp": "xxxxxxxxxx",
    "crimes": {
      "year": "6-2013",
      "region": [
        { "id": "North East", "total": "138982" },
        { "id": "North West", "total": "444423" }
        ....
        ....
               ],
      "national": [
        { "id": "British Transport Police", "total": "51968" },
        { "id": "Action Fraud", "total": "150389" }
                  ],
      "england": { "total": "3344716" },
      "wales": { "total": "173614" },
    }
  }
}


Here is what I have tried:

<?php
header('Content-type: application/json');
//content type applicable for xml format.
$data=simplexml_load_file("output.xml");
//Load the xml file into this file.
$json = array();
//create a new array for xml output.
$england = 0;
$wales = 0;
$find = 0;
//set new variables to distinguish between england and wales total crimes.
$json['response']['timestamp'] = time();
$json['response']['crimes']['year'] = '6-2013';
//get the current timestamp as well as the year posted from the convert to xml file page.
foreach($data->children() as $get_region)
{
if ($get_region->attributes()->{'id'} =="Action Fraud")
{
//if the children consists of data including the words 'ENGLAND AND WALES' then continue.
foreach ($get_region->children() as $area)
{
$json['response']['crimes']['national'][$find]['id'] = (string)$area['id'];
$json['response']['crimes']['national'][$find]['total'] = (int)$area->total_recorded_crime;
$find++; 
//get the totals                   
}
}
else
{
$json['response']['crimes']['region'][$find]['id'] = (string) $get_region->attributes()->{'id'};
//get the region names
$total = 0;
foreach ($get_region->children() as $area)
{
$total+= (int)$area->total_recorded_crime;
}
$json['response']['crimes']['region'][$find]['total'] = $total; 
if($get_region->attributes()->{'id'}!= "ENGLAND")
{
$england+=$total;
}
else
{
$wales+=$total;
//check if matches wales if not find totals for england.   
}
}
$find++; 
//continue finding the total rimes and place this within the national elements. 		
}
$json['response']['crimes']['england']['total'] = $england;
$json['response']['crimes']['wales']['total'] = $wales;
echo json_encode($json);
?>




Could anybody please point out where I am going wrong?

This post has been edited by Dormilich: 11 January 2014 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 10:01 AM

Please clarify: Do you specifically need to convert the XML into json?
If you just want to extract statistics from the XML then you could query the XML directly, rather than first converting the whole document into json.

And what does it output when you do this:
echo json_encode($json);

Was This Post Helpful? 0
  • +
  • -

#9 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

Re: http get XML to json

Posted 11 January 2014 - 10:10 AM

This is the output:
{"response":{"timestamp":1389458582,"crimes":{"year":"6-2013","region":[{"id":"North East Region","total":0},{"id":"North West Region","total":0},{"id":"Yorkshire and Humber Region","total":0},{"id":"East Midlands Region","total":0},{"id":"West Midlands Region","total":0},{"id":"East of England Region","total":0},{"id":"London Region","total":0},{"id":"South East Region","total":0},{"id":"South West Region","total":0},{"id":"WALES","total":0},{"id":"British Transport Police","total":0}],"national":{"11":{"id":"","total":0},"12":{"id":"Action Fraud","total":0}},"england":{"total":0},"wales":{"total":0}}}}



As you can see, all the totals are 0

I just need to pull specific statistics from the xml file.
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 10:19 AM

$json['response']['crimes']['national'][$find]['total'] = (int)$area->total_recorded_crime;

I've only glanced through this, but your earlier-posted XML nodes are named 'total' not 'total_recorded_crime'. If you are using the most recently linked-to xml then they are called 'total_recorded_crime', but each has two child-nodes excluding, and including, fraud.

Quote

I just need to pull specific statistics from the xml file.

If you are just extracting statistics, then is there still a need to convert the document to a json version?

This post has been edited by andrewsw: 11 January 2014 - 10:21 AM

Was This Post Helpful? 0
  • +
  • -

#11 hunter123   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 06-January 13

Re: http get XML to json

Posted 11 January 2014 - 10:24 AM

Yes I need to obtain a json output. Yes I am glad you noticed these two child nodes. Thats where I am struggling. How can I add both numbers contained in both nodes together innstead of using this - $json['response']['crimes']['national'][$find]['total'] = (int)$area->total_recorded_crime; as obviously total_recorded_crime is not the answer.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 10:42 AM

So you need to go one level further down, but I haven't explored this recently. Can we chain them together?
$area->total_recorded_crime->including_fraud

dunno :dontgetit: You'll want to remove the commas as well, if you want to perform arithmetic on the values.

BTW I'm sure there are plug-ins available that will convert XML directly to json ;) and then to remodel the json, removing nodes you don't need. Anyways.. I don't suppose you want to change your approach at this point.



The following probably isn't useful to you for your current task but, FWIW, XML can be calculated directly using DOMXPath.evaluate:
<?php

$doc = new DOMDocument;
$doc->load('file.xml');
$xpath = new DOMXPath($doc);

$sum_points = $xpath->evaluate('sum(//x/@points)');

print "Points: $sum_points\n";
?>

This post has been edited by andrewsw: 11 January 2014 - 10:43 AM

Was This Post Helpful? 0
  • +
  • -

#13 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 10:47 AM

XML to json:

$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

There are online resources as well google x2js
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 11:00 AM

Sorry that this is off-topic, but I was curious how well that Google tool worked:

Spoiler

I also ran it through a json formatter.

I realise that this is not directly helpful, but may be useful to others reading this topic.
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,944
  • Joined: 12-December 12

Re: http get XML to json

Posted 11 January 2014 - 11:36 AM

Personally, I think I would convert the XML to json in one go. It is easier to iterate, navigate, and modify, json than XML.

PHP will convert the XML to nested arrays. Keys can be removed using unset, and new keys added just with:
$json['akey']['anewkey'] = 'howdy';

Once complete you can use json_encode() again.

<?php
$animals = '{
 "0":{"kind":"mammal","name":"Pussy the Cat","weight":"12kg","age":"5"},
 "1":{"kind":"mammal","name":"Roxy the Dog","weight":"25kg","age":"8"},
 "2":{"kind":"fish","name":"Piranha the Fish","weight":"1kg","age":"1"},
 "3":{"kind":"bird","name":"Einstein the Parrot","weight":"0.5kg","age":"4"}
 }';

$animals = json_decode($animals, true);
foreach ($animals as $key => $value) {
    if (in_array('Piranha the Fish', $value)) {
        unset($animals[$key]);
    }
}
$animals = json_encode($animals);
?>

Anyway, I'll leave you alone now :)
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3