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

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

问题描述

我可能喜欢来解析下面的XML包含entrities。

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

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

解析工作。但entrities后,我没有收到任何输出。使用CDATA是不可能的位置。

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

我用下面的code:

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

有没有人有一个想法?

Does anyone got an idea?

THX提前!

推荐答案

我的名字是Divy DHIMAN我是一个资深Android开发

My name is Divy Dhiman i am a senior android developer

我已经通过同样的事情,你可以做到这一点通过实体或节点奥尔通过获取文字控件的取决于你做的XML解析。

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天全站免登陆