Android的DOM与标记实体解析实体、标记、Android、DOM

2023-09-04 06:23:47 作者:繁华落尽、承诺已殇!

我可能喜欢来解析下面的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;