简体   繁体   中英

Parsing part of xml file in Java(Android)

I have xml file like this:

<d-1>
   <zora>05:23</zora>
   <izlSunca>07:07</izlSunca>
   <podne>11:43</podne>
   <ikindija>13:53</ikindija>
   <aksam>16:17</aksam>
   <jacija>17:49</jacija>
</d-1>
<d-2>
   <zora>05:23</zora>
   <izlSunca>07:07</izlSunca>
   <podne>11:43</podne>
   <ikindija>13:54</ikindija>
   <aksam>16:18</aksam>
   <jacija>17:50</jacija>
</d-2>

I want to parse only values in tag d-1, how to do that?

I use SAX Parser..

Using Jdom, and assuming you have some root element...

    SAXBuilder builder = new  SAXBuilder();
    Document document = (Document)builder.build(new File("somedocument.xml"));

    Element root = document.getRootElement();
    Element d1 = root.getChild("d-1");
    String txt = d1.getChildText("zora");

I solved problem.. I edited xml file:

<dan value="1">
   <zora>05:23</zora>
   <izlSunca>07:07</izlSunca>
   <podne>11:43</podne>
   <ikindija>13:53</ikindija>
   <aksam>16:17</aksam>
   <jacija>17:49</jacija>
</dan>

and ask if value of day == 1 etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM