I am reading an XML file that lists forecast time steps for the weather. The forecasts are split up into days which contain a few time steps. I want to read the time steps all at one instead of going through each day at a time, how can I do this? This is the XML I am reading:
<Location i="3808" lat="50.218" lon="-5.33" name="CAMBORNE" country="ENGLAND" continent="EUROPE" elevation="87.0">
<Period type="Day" value="2014-08-16Z">
<Rep D="WSW" F="11" G="18" H="91" Pp="0" S="4" T="11" V="VG" W="1" U="1">360</Rep>
<Rep D="WNW" F="15" G="11" H="73" Pp="1" S="9" T="16" V="VG" W="3" U="1">540</Rep>
<Rep D="WNW" F="14" G="18" H="66" Pp="3" S="13" T="17" V="VG" W="3" U="4">720</Rep>
<Rep D="W" F="15" G="18" H="67" Pp="5" S="13" T="17" V="VG" W="7" U="5">900</Rep>
<Rep D="W" F="13" G="20" H="75" Pp="34" S="13" T="16" V="VG" W="7" U="1">1080</Rep>
<Rep D="WSW" F="12" G="18" H="83" Pp="7" S="9" T="14" V="VG" W="7" U="0">1260</Rep>
</Period>
<Period type="Day" value="2014-08-17Z">
<Rep D="W" F="12" G="20" H="83" Pp="38" S="11" T="14" V="VG" W="7" U="0">0</Rep>
<Rep D="W" F="12" G="18" H="85" Pp="8" S="11" T="14" V="VG" W="7" U="0">180</Rep>
<Rep D="W" F="12" G="20" H="86" Pp="53" S="11" T="14" V="VG" W="12" U="1">360</Rep>
<Rep D="WNW" F="13" G="22" H="79" Pp="30" S="16" T="16" V="VG" W="7" U="1">540</Rep>
<Rep D="WNW" F="13" G="25" H="87" Pp="53" S="16" T="16" V="GO" W="10" U="4">720</Rep>
<Rep D="NW" F="14" G="25" H="66" Pp="7" S="16" T="17" V="VG" W="3" U="3">900</Rep>
<Rep D="WNW" F="13" G="22" H="67" Pp="1" S="13" T="16" V="VG" W="1" U="2">1080</Rep>
<Rep D="WNW" F="12" G="16" H="79" Pp="1" S="9" T="14" V="VG" W="2" U="0">1260</Rep>
</Period>
<Period type="Day" value="2014-08-18Z">
...
</Period>
</Location>
And below is how I want to read it, but I don't want to change the file itself:
<Location i="3808" lat="50.218" lon="-5.33" name="CAMBORNE" country="ENGLAND" continent="EUROPE" elevation="87.0">
<Rep D="WSW" F="11" G="18" H="91" Pp="0" S="4" T="11" V="VG" W="1" U="1">360</Rep>
<Rep D="WNW" F="15" G="11" H="73" Pp="1" S="9" T="16" V="VG" W="3" U="1">540</Rep>
<Rep D="WNW" F="14" G="18" H="66" Pp="3" S="13" T="17" V="VG" W="3" U="4">720</Rep>
<Rep D="W" F="15" G="18" H="67" Pp="5" S="13" T="17" V="VG" W="7" U="5">900</Rep>
<Rep D="W" F="13" G="20" H="75" Pp="34" S="13" T="16" V="VG" W="7" U="1">1080</Rep>
<Rep D="WSW" F="12" G="18" H="83" Pp="7" S="9" T="14" V="VG" W="7" U="0">1260</Rep>
<Rep D="W" F="12" G="20" H="83" Pp="38" S="11" T="14" V="VG" W="7" U="0">0</Rep>
<Rep D="W" F="12" G="18" H="85" Pp="8" S="11" T="14" V="VG" W="7" U="0">180</Rep>
<Rep D="W" F="12" G="20" H="86" Pp="53" S="11" T="14" V="VG" W="12" U="1">360</Rep>
<Rep D="WNW" F="13" G="22" H="79" Pp="30" S="16" T="16" V="VG" W="7" U="1">540</Rep>
<Rep D="WNW" F="13" G="25" H="87" Pp="53" S="16" T="16" V="GO" W="10" U="4">720</Rep>
<Rep D="NW" F="14" G="25" H="66" Pp="7" S="16" T="17" V="VG" W="3" U="3">900</Rep>
<Rep D="WNW" F="13" G="22" H="67" Pp="1" S="13" T="16" V="VG" W="1" U="2">1080</Rep>
<Rep D="WNW" F="12" G="16" H="79" Pp="1" S="9" T="14" V="VG" W="2" U="0">1260</Rep>
...
</Location>
I don't want to go through all the periods and then go through all the reps inside each one, I just want to get all the reps at once. For example, I want to do:
foreach(rep in location)
Instead of:
foreach(period in location)
foreach(rep in period)
Without editing the file. Also, if I did this how would I find out which period a rep came from? Thanks
No comments:
Post a Comment