简体   繁体   English

如何在android中本地解析复杂的XML文件

[英]How to Parse Complex XML file Locally in android

How to parse this XML file locally in android ?如何在android中本地解析这个XML文件?

  <root>
        <Questions>
        <element>
          <answer>1</answer>
          <category>15</category>
          <date_added>2014-05-01 02:10:33</date_added>
          <id>7</id>
          <mode>easy</mode>
           <options>
               <element>2007</element>
               <element>2005</element>
               <element>2006</element>
               <element>2008</element>
            </options>
          <question>When did the first Apple iPhone become available?</question>
        </element>
         <element>
           <answer>3</answer>
           <category>13</category>
           <date_added>2014-05-01 02:14:30</date_added>
           <id>8</id>
           <mode>easy</mode>
            <options>
              <element>carnivores</element>
              <element>omnivores</element>
              <element>herbivores</element>
              <element>insectivores</element>
             </options>
         <question>Are Gorillas ______?</question>
         </element>
    </Questions>
 </root>

The above XML file is the file I have to parse locally.上面的 XML 文件是我必须在本地解析的文件。 I put the XML file into assets folder.我将 XML 文件放入资产文件夹。 It looks like a bit complex XML file.它看起来像一个有点复杂的 XML 文件。 I don't know how to parse this.我不知道如何解析这个。 Please help me for this.请帮我解决这个问题。 Each and every help will be deeply appreciated.每一个帮助都将受到深深的感激。 Thanks.谢谢。

Tons of libraries out there for XML parsing so it's hard to give a definite answer here.有大量用于 XML 解析的库,因此在这里很难给出明确的答案。 JDOM is pretty simple to use, you could give that a try :) JDOM使用起来非常简单,您可以尝试一下 :)

I got the answer.我得到了答案。 What i did was that, I convert the XML file to JSON file using a jar file and parsed from there.我所做的是,我使用 jar 文件将 XML 文件转换为 JSON 文件并从那里解析。 It works for me.这个对我有用。

Convert XML to JSON object in Android 在 Android 中将 XML 转换为 JSON 对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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