【问题标题】:Get Value from XML string从 XML 字符串中获取值
【发布时间】:2014-05-30 02:59:48
【问题描述】:

我试图从返回的 XML 响应中获取“msg”的值,如您所见,“msg”被找到了两次。如何从返回的响应中获取“msg”的所有值?

这里是一个返回值“msg”错误发现的示例:

<?xml version="1.0" encoding="UTF-8" ?>
<matches software="LanguageTool" version="2.6-SNAPSHOT" buildDate="2014-05-26 09:16">
  <language shortname="en-US" name="English (US)" />
  <error fromy="0" fromx="0" toy="0" tox="4" ruleId="UPPERCASE_SENTENCE_START" msg="This sentence does not start with an uppercase letter" replacements="This" context="this is a error" contextoffset="0" offset="0" errorlength="4" category="Capitalization" locqualityissuetype="typographical" />
  <error fromy="0" fromx="8" toy="0" tox="9" ruleId="EN_A_VS_AN" msg="Use 'an' instead of 'a' if the following word starts with a vowel sound, e.g. 'an article', 'an hour'" replacements="an" context="this is a error" contextoffset="8" offset="8" errorlength="1" category="Miscellaneous" locqualityissuetype="misspelling" />
</matches>

【问题讨论】:

    标签: java android xml api languagetool


    【解决方案1】:

    你可以试试https://developer.android.com/training/basics/network-ops/xml.html中描述的谷歌推荐的XML解析方法

    【讨论】:

      【解决方案2】:

      当涉及到 XML 解析时,这将是很大的帮助。

      http://www.sitepoint.com/learning-to-parse-xml-data-in-your-android-app/

      希望对您有所帮助。干杯!

      【讨论】:

        【解决方案3】:

        Simple 是一个用于 XML 的 Java 库,在 Android 上运行良好。 看 * http://simple.sourceforge.net/ * http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#deserialize * http://simple.sourceforge.net/download/stream/doc/examples/examples.php

        这个想法是将 XML 映射到 Java。该方法类似于 JaxB,但正如库名称所说的“更简单”。

        这是一个 sn-p,它可能会起作用

        @Root
        public class Match {
        
           @Path("error/[1]")
           @Attribute
           private String msg;
        
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-23
          • 2019-02-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多