<?xml version="1.0" encoding="utf-8"?> <dataList> <data><item>test</item></data> </dataList>
<?xml version="1.0" encoding="utf-8"?> <dataList> <data><item>test</item></data> </dataList>>
IService service = (IService) this .getBean("service"); FileInputStream fi = null; String url = servlet.getServletContext().getRealPath(File.separator) + "/data.xml"; SAXReader saxReader = new SAXReader(); fi = new FileInputStream(url); Document doc = saxReader.read(fi); Node item1 = doc.selectSingleNode("/dataList/data/item1"); Node item2 = doc.selectSingleNode("/dataList/data/item2"); Node item3 = doc.selectSingleNode("/dataList/data/item3"); Node item4 = doc.selectSingleNode("/dataList/data/item4"); Node item5 = doc.selectSingleNode("/dataList/data/item5"); Node item6 = doc.selectSingleNode("/dataList/data/item6"); Node item7 = doc.selectSingleNode("/dataList/data/item7"); Node item8 = doc.selectSingleNode("/dataList/data/item8"); Node item9 = doc.selectSingleNode("/dataList/data/item9"); Node item10 = doc.selectSingleNode("/dataList/data/item10"); Node item11 = doc.selectSingleNode("/dataList/data/item11"); Node item12 = doc.selectSingleNode("/dataList/data/item12"); Node item13 = doc.selectSingleNode("/dataList/data/item10"); Node item21 = doc.selectSingleNode("/dataList/data/item21"); Node item22 = doc.selectSingleNode("/dataList/data/item22"); Node item23 = doc.selectSingleNode("/dataList/data/item23"); Node item31 = doc.selectSingleNode("/dataList/data/item31"); Node item32 = doc.selectSingleNode("/dataList/data/item32"); Node item33 = doc.selectSingleNode("/dataList/data/item33"); Node item41 = doc.selectSingleNode("/dataList/data/item41"); Node item42 = doc.selectSingleNode("/dataList/data/item42"); Node item43 = doc.selectSingleNode("/dataList/data/item43"); Node item51 = doc.selectSingleNode("/dataList/data/item51"); Node item52 = doc.selectSingleNode("/dataList/data/item52"); Node item53 = doc.selectSingleNode("/dataList/data/item53"); Node item61 = doc.selectSingleNode("/dataList/data/item61"); Node item62 = doc.selectSingleNode("/dataList/data/item62"); Node item63 = doc.selectSingleNode("/dataList/data/item63"); Node item71 = doc.selectSingleNode("/dataList/data/item71"); Node item72 = doc.selectSingleNode("/dataList/data/item72"); Node item73 = doc.selectSingleNode("/dataList/data/item73"); Node item81 = doc.selectSingleNode("/dataList/data/item81"); Node item82 = doc.selectSingleNode("/dataList/data/item82"); Node item83 = doc.selectSingleNode("/dataList/data/item83"); Node temperature = doc.selectSingleNode("/dataList/data/temperature"); Node humidity = doc.selectSingleNode("/dataList/data/humidity"); Node item91 = doc.selectSingleNode("/dataList/data/item91"); Node item92 = doc.selectSingleNode("/dataList/data/item92"); Node item93 = doc.selectSingleNode("/dataList/data/item93"); Node item94 = doc.selectSingleNode("/dataList/data/item94"); Node item95 = doc.selectSingleNode("/dataList/data/item95"); Node item96 = doc.selectSingleNode("/dataList/data/item96"); Node item97 = doc.selectSingleNode("/dataList/data/item97"); Node item98 = doc.selectSingleNode("/dataList/data/item98"); Node item99 = doc.selectSingleNode("/dataList/data/item99"); Node item910 = doc.selectSingleNode("/dataList/data/item910"); Node item911 = doc.selectSingleNode("/dataList/data/item911"); Node item912 = doc.selectSingleNode("/dataList/data/item912"); Node item913 = doc.selectSingleNode("/dataList/data/item913"); Node item914 = doc.selectSingleNode("/dataList/data/item914"); Node item915 = doc.selectSingleNode("/dataList/data/item915"); Node item916 = doc.selectSingleNode("/dataList/data/item916"); Node item101 = doc.selectSingleNode("/dataList/data/item101"); Node item102 = doc.selectSingleNode("/dataList/data/item102"); Node item111 = doc.selectSingleNode("/dataList/data/item111"); Node item112 = doc.selectSingleNode("/dataList/data/item112"); WatTemperatureandhumidity wth = (WatTemperatureandhumidity) service .getWaterTemperatureAndHumidity(); temperature.setText(wth.getTemperature().toString()); humidity.setText(wth.getHumidity().toString()); item1.setText("" + Math.floor(Math.random() * 20)); item2.setText("" + Math.floor(Math.random() * 99)); item3.setText("" + Math.floor(Math.random() * 20)); item4.setText("" + Math.floor(Math.random() * 99)); item5.setText("" + Math.floor(Math.random() * 20)); item6.setText("" + Math.floor(Math.random() * 99)); item7.setText("" + Math.floor(Math.random() * 20)); item8.setText("" + Math.floor(Math.random() * 99)); item9.setText("" + Math.floor(Math.random() * 20)); item10.setText("" + Math.floor(Math.random() * 99)); item11.setText("".equals(item12.getText()) ? "" : "44"); item12.setText("" + Math.floor(Math.random() * 99)); item13.setText("" + Math.floor(Math.random() * 20)); item21.setText("" + Math.floor(Math.random() * 99)); item22.setText("" + Math.floor(Math.random() * 20)); item23.setText("" + Math.floor(Math.random() * 99)); item31.setText("" + Math.floor(Math.random() * 20)); item32.setText("" + Math.floor(Math.random() * 99)); item33.setText("" + Math.floor(Math.random() * 20)); item41.setText("" + Math.floor(Math.random() * 99)); item42.setText("" + Math.floor(Math.random() * 20)); item43.setText("" + Math.floor(Math.random() * 99)); item51.setText("" + Math.floor(Math.random() * 99)); item52.setText("" + Math.floor(Math.random() * 20)); item53.setText("" + Math.floor(Math.random() * 99)); item61.setText("" + Math.floor(Math.random() * 20)); item62.setText("" + Math.floor(Math.random() * 99)); item63.setText("" + Math.floor(Math.random() * 20)); item71.setText("" + Math.floor(Math.random() * 99)); item72.setText("" + Math.floor(Math.random() * 20)); item73.setText("" + Math.floor(Math.random() * 99)); item81.setText("" + Math.floor(Math.random() * 20)); item82.setText("" + Math.floor(Math.random() * 99)); item83.setText("" + Math.floor(Math.random() * 20)); item91.setText("" + Math.floor(Math.random() * 20)); item92.setText("" + Math.floor(Math.random() * 99)); item93.setText("" + Math.floor(Math.random() * 20)); item94.setText("" + Math.floor(Math.random() * 99)); item95.setText("" + Math.floor(Math.random() * 20)); item96.setText("" + Math.floor(Math.random() * 99)); item97.setText("" + Math.floor(Math.random() * 20)); item98.setText("" + Math.floor(Math.random() * 99)); item99.setText("" + Math.floor(Math.random() * 20)); item910.setText("" + Math.floor(Math.random() * 99)); item911.setText("" + Math.floor(Math.random() * 20)); item912.setText("" + Math.floor(Math.random() * 99)); item913.setText("" + Math.floor(Math.random() * 20)); item914.setText("" + Math.floor(Math.random() * 99)); item915.setText("" + Math.floor(Math.random() * 20)); item916.setText("" + Math.floor(Math.random() * 99)); item101.setText("" + Math.floor(Math.random() * 20)); item102.setText("" + Math.floor(Math.random() * 99)); item111.setText("" + Math.floor(Math.random() * 20)); item112.setText("" + Math.floor(Math.random() * 99)); FileOutputStream fos = new FileOutputStream(url); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, "utf-8")); XMLWriter writer = new XMLWriter(bw); writer.write(doc); bw.close(); return null;
<?xml version="1.0" encoding="utf-8"?> <dataList> <data> <item1>24.41</item1> <item2>12.59</item2> <item3>6.2</item3> <item4>10</item4> <item5>304</item5> <item6>33</item6> <item7>0.00</item7> <item8>128</item8> <item9>69.9</item9> <item10>1.9</item10> <item11>开机</item11> <item12>26</item12> <item13>128</item13> <item21>停机</item21> <item22>26</item22> <item23>128</item23> <item31>开机</item31> <item32>26</item32> <item33>128</item33> <item41>-</item41> <item42>26</item42> <item43>128</item43> <item51>-</item51> <item52>26</item52> <item53>128</item53> <item61>-</item61> <item62>26</item62> <item63>128</item63> <item71>-</item71> <item72>26</item72> <item73>128</item73> <item81>-</item81> <item82>26</item82> <item83>128</item83> <temperature>23.9</temperature> <humidity>99.9</humidity> <item91>2.41</item91> <item92>2.59</item92> <item93>0</item93> <item94>0</item94> <item95>4</item95> <item96>3</item96> <item97>0.00</item97> <item98>8</item98> <item99>0.9</item99> <item910>4.41</item910> <item911>2.41</item911> <item912>2.59</item912> <item913>6.82</item913> <item914>0</item914> <item915>4</item915> <item916>3</item916> <item101>6.9</item101> <item102>9.9</item102> <item111>0.9</item111> <item112>9.9</item112> </data> </dataList>