如何将XML字符串解析为String [] [英] How to Parse XML string to String[]

查看:79
本文介绍了如何将XML字符串解析为String []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将以下xml字符串转换为String []

How to convert following xml string to String[]

<?xml version=1.0 encoding=UTF-8 standalone=yes?>
<NewDataSet>
<WHDS>
  <WHBILL>
    <TrnDate>14-Oct-2014</TrnDate>
    <FromDate>01-Oct-2014</FromDate>
    <ToDate>31-Oct-2014</ToDate>
    <Location>Gujarat</Location>
    <ClientCode>1001</ClientCode>
    <ClientName>abc</ClientName>
    <WarehouseCode>g001</WarehouseCode>
    <WarehouseName>g1</WarehouseName>
    <ServiceTaxApplicable>y</ServiceTaxApplicable>
    <RefVouchNo>1</RefVouchNo>
    <StorageCharges>2000</StorageCharges>
  </WHBILL>
</WHDS>
</NewDataSet>










 String xmlString;
Document doc=getDomElement(xmlString);

public Document getDomElement(String xml) {
        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is);

        } catch (ParserConfigurationException e) {
            Log.e("Error: ", e.getMessage());
             return null;
        } catch (SAXException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.e("Error: ", e.getMessage());
            return null;
        }
        return doc;
    }



[/编辑 - 内容已从评论中移除]

请帮帮我。


[/EDIT - content moved from comment]
Please Help me.

推荐答案

看看这里: http://stackoverflow.com/questions/4161256/android-reference-a-string-in-a-string-array-resource-with-xml [ ^ ]在这里: http://stackoverflow.com/questions/19876488/android-string -array-from-xml-file-to-listview [ ^ ]



如需了解更多信息,请参阅: http://developer.android.com/guide/topics/resources/string-resource.html [ ^ ]
Have a look here: http://stackoverflow.com/questions/4161256/android-reference-a-string-in-a-string-array-resource-with-xml[^] and here: http://stackoverflow.com/questions/19876488/android-string-array-from-xml-file-to-listview[^]

For further information, please see: http://developer.android.com/guide/topics/resources/string-resource.html[^]


这篇关于如何将XML字符串解析为String []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆