5

我有这个 xml 文件,我想将其转换为数据框:

数据.xml

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <graph_data xmlns:ns2="http://www.w3.org/2005/Atom">
  <graph_property name="calculation_method" value="Geo Mean" /> 
  <graph_property name="graph_type" value="TIME" /> 
- <measurement id="521406">
  <alias>site4</alias> 
- <bucket_data>
- <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="21" /> 
  <perf_data unit="seconds" value="3.102" /> 
  </bucket>
- <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="3.052" /> 
  </bucket>
- <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="3.387" /> 
  </bucket>
- <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="3.338" /> 
  </bucket>
- <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.149" /> 
  </bucket>
- <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="3.202" /> 
  </bucket>
- <bucket id="7" name="2013-MAY-14 01:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="2.883" /> 
  </bucket>
- <bucket id="8" name="2013-MAY-14 02:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="2.582" /> 
  </bucket>
- <bucket id="9" name="2013-MAY-14 03:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.769" /> 
  </bucket>
- <bucket id="10" name="2013-MAY-14 04:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="2.669" /> 
  </bucket>
- <bucket id="11" name="2013-MAY-14 05:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="2.830" /> 
  </bucket>
- <bucket id="12" name="2013-MAY-14 06:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="2.591" /> 
  </bucket>
- <bucket id="13" name="2013-MAY-14 07:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="3.213" /> 
  </bucket>
- <bucket id="14" name="2013-MAY-14 08:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.653" /> 
  </bucket>
- <bucket id="15" name="2013-MAY-14 09:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.935" /> 
  </bucket>
- <bucket id="16" name="2013-MAY-14 10:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="2.495" /> 
  </bucket>
- <bucket id="17" name="2013-MAY-14 11:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="3.169" /> 
  </bucket>
- <bucket id="18" name="2013-MAY-15 12:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="2.789" /> 
  </bucket>
- <bucket id="19" name="2013-MAY-15 01:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="3.245" /> 
  </bucket>
- <bucket id="20" name="2013-MAY-15 02:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="3.281" /> 
  </bucket>
- <bucket id="21" name="2013-MAY-15 03:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="3.773" /> 
  </bucket>
- <bucket id="22" name="2013-MAY-15 04:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="21" /> 
  <perf_data unit="seconds" value="2.648" /> 
  </bucket>
- <bucket id="23" name="2013-MAY-15 05:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="3.291" /> 
  </bucket>
- <bucket id="24" name="2013-MAY-15 06:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="3.084" /> 
  </bucket>
  </bucket_data>
- <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="2.949" /> 
  <data_cell name="avg_avail" unit="percent" value="100.00" /> 
  <data_cell name="total_datapoint_count" unit="#" value="347" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
- <measurement id="521406">
  <alias>Site3</alias> 
- <bucket_data>
- <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="85.71" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="6.503" /> 
  </bucket>
- <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="6.330" /> 
  </bucket>
- <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="7.242" /> 
  </bucket>
- <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="93.33" /> 
  <data_count unit="#" value="14" /> 
  <perf_data unit="seconds" value="7.083" /> 
  </bucket>
- <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="7.087" /> 
  </bucket>
- <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="76.92" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="6.197" /> 
  </bucket>
- <bucket id="7" name="2013-MAY-14 01:00 PM">
  <avail_data unit="percent" value="83.33" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="6.772" /> 
  </bucket>
- <bucket id="8" name="2013-MAY-14 02:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="5.832" /> 
  </bucket>
- <bucket id="9" name="2013-MAY-14 03:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="8.513" /> 
  </bucket>
- <bucket id="10" name="2013-MAY-14 04:00 PM">
  <avail_data unit="percent" value="91.67" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="7.190" /> 
  </bucket>
- <bucket id="11" name="2013-MAY-14 05:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="6.373" /> 
  </bucket>
- <bucket id="12" name="2013-MAY-14 06:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="8.440" /> 
  </bucket>
- <bucket id="13" name="2013-MAY-14 07:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="6.318" /> 
  </bucket>
- <bucket id="14" name="2013-MAY-14 08:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="6.374" /> 
  </bucket>
- <bucket id="15" name="2013-MAY-14 09:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="6.773" /> 
  </bucket>
- <bucket id="16" name="2013-MAY-14 10:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="6.274" /> 
  </bucket>
- <bucket id="17" name="2013-MAY-14 11:00 PM">
  <avail_data unit="percent" value="90.00" /> 
  <data_count unit="#" value="9" /> 
  <perf_data unit="seconds" value="5.881" /> 
  </bucket>
- <bucket id="18" name="2013-MAY-15 12:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="5.630" /> 
  </bucket>
- <bucket id="19" name="2013-MAY-15 01:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="6.585" /> 
  </bucket>
- <bucket id="20" name="2013-MAY-15 02:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="7.394" /> 
  </bucket>
- <bucket id="21" name="2013-MAY-15 03:00 AM">
  <avail_data unit="percent" value="91.67" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="6.427" /> 
  </bucket>
- <bucket id="22" name="2013-MAY-15 04:00 AM">
  <avail_data unit="percent" value="95.24" /> 
  <data_count unit="#" value="20" /> 
  <perf_data unit="seconds" value="7.140" /> 
  </bucket>
- <bucket id="23" name="2013-MAY-15 05:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="7.152" /> 
  </bucket>
- <bucket id="24" name="2013-MAY-15 06:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="6.474" /> 
  </bucket>
  </bucket_data>
- <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="6.729" /> 
  <data_cell name="avg_avail" unit="percent" value="95.97" /> 
  <data_cell name="total_datapoint_count" unit="#" value="347" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
- <measurement id="521406">
  <alias>Site2</alias> 
- <bucket_data>
- <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="2.247" /> 
  </bucket>
- <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="2.382" /> 
  </bucket>
- <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.232" /> 
  </bucket>
- <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="14" /> 
  <perf_data unit="seconds" value="2.223" /> 
  </bucket>
- <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.265" /> 
  </bucket>
- <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.130" /> 
  </bucket>
- <bucket id="7" name="2013-MAY-14 01:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.153" /> 
  </bucket>
- <bucket id="8" name="2013-MAY-14 02:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="2.005" /> 
  </bucket>
- <bucket id="9" name="2013-MAY-14 03:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.322" /> 
  </bucket>
- <bucket id="10" name="2013-MAY-14 04:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="1.918" /> 
  </bucket>
- <bucket id="11" name="2013-MAY-14 05:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="1.992" /> 
  </bucket>
- <bucket id="12" name="2013-MAY-14 06:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="2.423" /> 
  </bucket>
- <bucket id="13" name="2013-MAY-14 07:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="2.327" /> 
  </bucket>
- <bucket id="14" name="2013-MAY-14 08:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.605" /> 
  </bucket>
- <bucket id="15" name="2013-MAY-14 09:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="2.533" /> 
  </bucket>
- <bucket id="16" name="2013-MAY-14 10:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="2.077" /> 
  </bucket>
- <bucket id="17" name="2013-MAY-14 11:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="9" /> 
  <perf_data unit="seconds" value="2.356" /> 
  </bucket>
- <bucket id="18" name="2013-MAY-15 12:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="2.506" /> 
  </bucket>
- <bucket id="19" name="2013-MAY-15 01:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="2.422" /> 
  </bucket>
- <bucket id="20" name="2013-MAY-15 02:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="2.220" /> 
  </bucket>
- <bucket id="21" name="2013-MAY-15 03:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="2.669" /> 
  </bucket>
- <bucket id="22" name="2013-MAY-15 04:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="20" /> 
  <perf_data unit="seconds" value="2.274" /> 
  </bucket>
- <bucket id="23" name="2013-MAY-15 05:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="2.277" /> 
  </bucket>
- <bucket id="24" name="2013-MAY-15 06:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="2.180" /> 
  </bucket>
  </bucket_data>
- <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="2.269" /> 
  <data_cell name="avg_avail" unit="percent" value="100.00" /> 
  <data_cell name="total_datapoint_count" unit="#" value="333" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
- <measurement id="521406">
  <alias>Site1</alias> 
- <bucket_data>
- <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="1.431" /> 
  </bucket>
- <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="1.559" /> 
  </bucket>
- <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="1.378" /> 
  </bucket>
- <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="14" /> 
  <perf_data unit="seconds" value="1.307" /> 
  </bucket>
- <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="1.458" /> 
  </bucket>
- <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="1.345" /> 
  </bucket>
- <bucket id="7" name="2013-MAY-14 01:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="1.317" /> 
  </bucket>
- <bucket id="8" name="2013-MAY-14 02:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="1.465" /> 
  </bucket>
- <bucket id="9" name="2013-MAY-14 03:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="1.398" /> 
  </bucket>
- <bucket id="10" name="2013-MAY-14 04:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="1.509" /> 
  </bucket>
- <bucket id="11" name="2013-MAY-14 05:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="1.284" /> 
  </bucket>
- <bucket id="12" name="2013-MAY-14 06:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="1.759" /> 
  </bucket>
- <bucket id="13" name="2013-MAY-14 07:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="1.434" /> 
  </bucket>
- <bucket id="14" name="2013-MAY-14 08:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="1.402" /> 
  </bucket>
- <bucket id="15" name="2013-MAY-14 09:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="1.452" /> 
  </bucket>
- <bucket id="16" name="2013-MAY-14 10:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="1.216" /> 
  </bucket>
- <bucket id="17" name="2013-MAY-14 11:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="9" /> 
  <perf_data unit="seconds" value="1.381" /> 
  </bucket>
- <bucket id="18" name="2013-MAY-15 12:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="1.236" /> 
  </bucket>
- <bucket id="19" name="2013-MAY-15 01:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="16" /> 
  <perf_data unit="seconds" value="1.327" /> 
  </bucket>
- <bucket id="20" name="2013-MAY-15 02:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="17" /> 
  <perf_data unit="seconds" value="1.465" /> 
  </bucket>
- <bucket id="21" name="2013-MAY-15 03:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="1.529" /> 
  </bucket>
- <bucket id="22" name="2013-MAY-15 04:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="20" /> 
  <perf_data unit="seconds" value="1.354" /> 
  </bucket>
- <bucket id="23" name="2013-MAY-15 05:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="11" /> 
  <perf_data unit="seconds" value="1.372" /> 
  </bucket>
- <bucket id="24" name="2013-MAY-15 06:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="12" /> 
  <perf_data unit="seconds" value="1.219" /> 
  </bucket>
  </bucket_data>
- <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="1.387" /> 
  <data_cell name="avg_avail" unit="percent" value="100.00" /> 
  <data_cell name="total_datapoint_count" unit="#" value="333" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
  <ns2:link href="www.example.com" rel="slotmetadata" type="application/xml" /> 
  </graph_data>

我的数据框需要如下所示:

alias  bucket_name avail_data perf_data

我试过这个:

doc1 = xmlParse("data.xml")
df<-xmlToDataFrame(nodes = getNodeSet(doc1, "//alias"))

我只在一个列数据框中获取别名。任何想法我在这里还缺少什么?

有文件

4

1 回答 1

2

看起来您的 XML 有一些问题。我只能通过删除以下内容来使其工作:

Line 58: <measurement id="521406">
Line 107: <measurement id="521406">

所以:

xml_file <- '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
  <graph_data xmlns:ns2="http://www.w3.org/2005/Atom">
  <graph_property name="calculation_method" value="Geo Mean" /> 
  <graph_property name="graph_type" value="TIME" /> <measurement id="521406">
  <alias>example1.com</alias> 
  <bucket_data>
  <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="21" /> 
  <perf_data unit="seconds" value="3.102" /> 
  </bucket>
  <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="3.052" /> 
  </bucket>
  <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="3.387" /> 
  </bucket>
  <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="3.338" /> 
  </bucket>
  <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="2.149" /> 
  </bucket>
  <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="3.202" /> 
  </bucket>
  <bucket id="7" name="2013-MAY-14 01:00 PM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="2.883" /> 
  </bucket>
  </bucket_data>
  <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="2.949" /> 
  <data_cell name="avg_avail" unit="percent" value="100.00" /> 
  <data_cell name="total_datapoint_count" unit="#" value="347" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
  <measurement id="521406">
  <alias>example2.com</alias> 
  <bucket_data>
  <bucket id="1" name="2013-MAY-14 07:00 AM">
  <avail_data unit="percent" value="85.71" /> 
  <data_count unit="#" value="18" /> 
  <perf_data unit="seconds" value="6.503" /> 
  </bucket>
  <bucket id="2" name="2013-MAY-14 08:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="13" /> 
  <perf_data unit="seconds" value="6.330" /> 
  </bucket>
  <bucket id="3" name="2013-MAY-14 09:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="15" /> 
  <perf_data unit="seconds" value="7.242" /> 
  </bucket>
  <bucket id="4" name="2013-MAY-14 10:00 AM">
  <avail_data unit="percent" value="93.33" /> 
  <data_count unit="#" value="14" /> 
  <perf_data unit="seconds" value="7.083" /> 
  </bucket>
  <bucket id="5" name="2013-MAY-14 11:00 AM">
  <avail_data unit="percent" value="100.00" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="7.087" /> 
  </bucket>
  <bucket id="6" name="2013-MAY-14 12:00 PM">
  <avail_data unit="percent" value="76.92" /> 
  <data_count unit="#" value="10" /> 
  <perf_data unit="seconds" value="6.197" /> 
  </bucket>
  </bucket_data>
  <graph_option>
  <data_cell name="perfwarning" unit="seconds" value="-" /> 
  <data_cell name="perfcritical" unit="seconds" value="-" /> 
  <data_cell name="availwarning" unit="percent" value="-" /> 
  <data_cell name="availcritical" unit="percent" value="-" /> 
  <data_cell name="bucketsize" unit="seconds" value="3600" /> 
  <data_cell name="rows" unit="#" value="24" /> 
  <data_cell name="pagecomponent" unit="seconds" value="Total Time" /> 
  <data_cell name="avg_perf" unit="seconds" value="6.729" /> 
  <data_cell name="avg_avail" unit="percent" value="95.97" /> 
  <data_cell name="total_datapoint_count" unit="#" value="347" /> 
  <data_cell /> 
  </graph_option>
  </measurement>
  </graph_data>'

xml_file <- xmlParse(xml_file)    # Parse the XML
xml_file <- xmlToList(xml_file)   # Convert the XML to a list

我将它转换为列表而不是数据框,因为 XML 似乎不遵循易于转换为行和列的结构。之后,根据您的问题,我只提取了“测量”节点的“别名”或“bucket_data”部分中包含的信息:

xml_file <- xml_file[names(xml_file) == "measurement"]
xml_file <- lapply(xml_file, function(x) x[grep("alias|bucket", names(x))])

然后我遍历每个测量节点,将别名信息放在一边,将桶列表变成一个命名向量,然后将别名和桶绑定到列中。最后,我将测量节点绑定成行并将整个事物转换为数据框。

xml_file <- lapply(xml_file, function(x) {
  alias <- x$alias
  buckets <- t(sapply(x$bucket_data, unlist))
  cbind("alias" = alias, buckets)
})

xml_file <- do.call("rbind", xml_file)

xml_file <- data.frame(xml_file, stringsAsFactors = FALSE)
Warning message:
In data.row.names(row.names, rowsi, i) :
  some row.names duplicated: 2,3,4,5,6,7,8,9,10,11,12,13 --> row.names NOT used

str(xml_file)
'data.frame':   13 obs. of  9 variables:
 $ alias           : chr  "example1.com" "example1.com" "example1.com" "example1.com" ...
 $ avail_data.unit : chr  "percent" "percent" "percent" "percent" ...
 $ avail_data.value: chr  "100.00" "100.00" "100.00" "100.00" ...
 $ data_count.unit : chr  "#" "#" "#" "#" ...
 $ data_count.value: chr  "21" "13" "15" "15" ...
 $ perf_data.unit  : chr  "seconds" "seconds" "seconds" "seconds" ...
 $ perf_data.value : chr  "3.102" "3.052" "3.387" "3.338" ...
 $ .attrs.id       : chr  "1" "2" "3" "4" ...
 $ .attrs.name     : chr  "2013-MAY-14 07:00 AM" "2013-MAY-14 08:00 AM" "2013-MAY-14 09:00 AM" "2013-MAY-14 10:00 AM" ...

您仍然需要清理列名并将列转换为适当的类,但它会将您的数据放入数据框中。

于 2013-05-16T14:24:26.893 回答