android DOM解析与标签中的实体 [英] android DOM parsing with entities in tags

查看:18
本文介绍了android DOM解析与标签中的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能想解析以下包含条目的 XML.

I might like to parse the following XML that contains entrities.

<node>
    <text><title>foo fo &lt;BR&gt;bar bar </title></text>
</node>

解析有效.但是在条目之后我没有收到任何输出.无法在该位置使用 CDATA.

The parsing works. But after the entrities I do not receive any output. Using CDATA is not possible at the position.

我正在使用以下代码:

        urlConnection.getInputStream());
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setExpandEntityReferences(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(in);

有人知道吗?

提前谢谢!

推荐答案

我叫 Divy Dhiman 我是一名资深的安卓开发者

My name is Divy Dhiman i am a senior android developer

我已经完成了 XML 解析,您可以通过实体或节点 aur 进行解析,方法是获取取决于您的文字控制.

I had done the XML parsing by the same thing you can do it by entity or by node aur by fetching literal control that's depend on you.

私有类 MyAsyncTask 扩展 AsyncTask{

private class MyAsyncTask extends AsyncTask {

    @Override
    protected String doInBackground(String... abc) {

        try {

            URL url = new URL(jksbvlds);

            URLConnection connection;
            connection = url.openConnection();

            HttpURLConnection httpConnection = (HttpURLConnection) connection;
             int responseCode = httpConnection.getResponseCode();
             if(responseCode == HttpURLConnection.HTTP_OK)
             {

                 InputStream in = httpConnection.getInputStream();
                 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                 DocumentBuilder db = dbf.newDocumentBuilder();
                 Document dom = db.parse(in);

                 Element docEle = dom.getDocumentElement();
                 NodeList nl = docEle.getElementsByTagName("quote");
                 if(nl != null && nl.getLength()>0)
                 {
                     for(int i = 0; i<nl.getLength();i++ )
                     {
                         StockInfo theStock = getStockInformation(docEle);


                         name = theStock.getName();
                         yearLow = theStock.getYearLow();
                         yearHigh = theStock.getYearHigh();
                         daysLow = theStock.getDaysLow();
                         daysHigh = theStock.getDaysHigh();
                         lastTradePriceonly = theStock.getLastTradePriceonly();
                         change = theStock.getChange();
                         daysRange = theStock.getDaysRange();

                     }
                 }



             }

        } 

        catch(MalformedURLException e)
        {
            Log.d(TAG,"MalformedURLException",e);
        }
        catch(IOException e)
        {
            Log.d(TAG,"IOException",e);
        }
        catch (ParserConfigurationException e) {
            Log.d(TAG,"ParserConfigurationException", e);
            }
        catch (SAXException e) {
            Log.d(TAG,"SAXException",e);

        }
        finally{}

        return null;

这篇关于android DOM解析与标签中的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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