【问题标题】:Parse ISO8583 XML in android (using android studio)在 android 中解析 ISO8583 XML(使用 android studio)
【发布时间】:2016-02-11 16:56:29
【问题描述】:

我有这个想要在 android (android studio) 中解析的 XML。有人请帮忙。我真的卡在这里了。

<?xml version="1.0" encoding="utf-8"?> 
<message> 
<isomsg direction="response">
<field id="0" value="ew8wqq"/>
<field id="2" value="kdlaka"/>
<field id="3" value="3388382"/>
<field id="4" value="9302"/>
<field id="7" value="02061212223721"/>
<field id="11" value="9029221"/>
<field id="12" value="38383"/>
<field id="24" value="0920202"/>
<field id="32" value="Texted"/>
<field id="37" value="10031503992006830"/>
<field id="41" value="93039292"/>
<field id="49" value="uehee"/>
<field id="56" value="938339939393"/>
<field id="68" value="Test: 5001115750001"/>
<field id="102" value="5001115750001"/>
<field id="27" value="001"/>
<field id="39" value="00"/>
<field id="48" value="Successful"/>
<field id="54" value="38288928383"/>
<field id="58" value="73838383"/>
</isomsg> 
</message>

我会很感激的。非常感谢

请在下面找到我用来从网络服务获取响应的代码

SoapObject request = new SoapObject("http://tempuri.org/", "PostRequest");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
PropertyInfo pi = new PropertyInfo();
pi.setName("IncomingXMLMessage");

pi.setValue(GenerateXML());

request.addProperty(pi);
envelope.setOutputSoapObject(request);

HttpTransportSE httpTransportSE = new HttpTransportSE("http://10.100.10.10:9000/IWalletService.asmx");
SoapObject response = null;
httpTransportSE.debug=true;             

httpTransportSE.call("http://tempuri.org/PostRequest", envelope);

response = (SoapObject)envelope.bodyIn;

int totalCount = response.getPropertyCount();
String resultString=httpTransportSE.responseDump;
Log.d("XML data ", resultString);

XmlPullParserFactory factory = XmlPullParserFactory
        .newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();

String uResultString=resultString.replaceAll("&gt;", ">");

String uResultStringFinal=uResultString.replaceAll("&lt;","<");

parser.setInput(new StringReader(uResultStringFinal));

【问题讨论】:

    标签: android xml parsing iso8583 jpos


    【解决方案1】:

    为了在 Android 中解析您的 xml 数据,您显然需要为此使用解析器。谷歌建议XmlPullParser 我自己发现它非常有用。 Google 还为此here 提供了一些示例代码。在这里解释所有内容只是对这个完全相同的问题的其他答案的重复。如果 Google 的代码还不够,你可以在网上搜索一些其他教程!

    【讨论】:

    • 我查看了给出的解释和示例,但我似乎无法理解。我无法理解。侧风,请协助
    • 我正在从 o Web 服务获取此 XML 并转换为字符串。响应 = (SoapObject)envelope.bodyIn; int totalCount = response.getPropertyCount();字符串结果字符串=httpTransportSE.responseDump;所以我在将此值发布到此方法时遇到问题 private String readFields(XmlPullParser parser),......它只接受解析器。如何将此 xml 字符串转换为解析器?
    • 老实说,我不知道你在那里做什么。您通常会实例化您的解析器等,然后为该解析器设置一个输入,该解析器采用 Reader 或 InputStream。也许我的例子会对你有所帮助 - github.com/Crosswind/Vertretungsplan/blob/master/app/src/main/… 你究竟是从哪里得到 xml 的?下载的文件?
    • 感谢您的反馈。我正在从网络服务中获得响应。我正在使用 kspoap2 发布请求并获得响应。现在的问题是解析响应并向用户显示必要的字段
    • 请使用您用于获取 XML 的代码编辑您的帖子,因为我相信这会使事情变得更容易。
    【解决方案2】:

    这是嵌套在 &lt;message&gt;&lt;/message&gt; 中的 JPOS 响应 XML,而不是 SOAP XML,

    看看 JPOS 是如何解析的:https://github.com/jpos/jPOS/blob/master/jpos/src/main/java/org/jpos/iso/packager/XMLPackager.java#L117

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-15
      • 2021-12-24
      • 2020-04-05
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多