cat_desc 标签无法完全解析并且无法在 webview 中正确显示

发布于 2024-12-11 16:33:30 字数 6040 浏览 0 评论 0原文

首先请检查网址*http://mobileecommerce.site247365.com/admin/catdata.xml * 谷歌浏览器。我面临两个问题 1. 对于 xml 中的第二个 cat_desccat_name E n I Sept 未显示在 webview 上。我认为这是因为它的 cat_desc 在表格样式标记的第一行包含 % 符号 <"table style="border-collapse:collapse;width :100%;"> 如何忽略% 符号?

2。第二个问题是,从最后一个带有 cat_name Handouts 的第三个标签开始,在解析 cat_desc 时会产生问题。它不会完全解析它的最后一个三行没有解析。我也会在日志中检查它,但最后三行没有解析。为什么会这样?对于其他 cat_desc 解析得很好并且在 webview 上运行良好。

public class FirstActivity extends ListActivity implements OnItemClickListener {
/** called when the activity is first created. */

String[] cat_name=null;
String[] cat_desc=null;
ListView optionslist=null;
NewsListAdapter adapter=null;
ArrayList<NewsItem> getArray=null;
ArrayAdapter<String> arrayadapter=null;
HashMap<String, String> hashamp=null;



public static final String url="http://mobileecommerce.site247365.com/admin/catdata.xml";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    innitializeUIComponents();
    new RefreshArrayFromInternet().execute(url);


}

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

    Log.v("in position", ""+position);

    String str=new String(getArray.get(position).getCatdesc());
    Log.v("on item click desc", str);
    Intent intent=new Intent(FirstActivity.this, WebviewActivity.class);
    intent.putExtra("str",str);
    startActivity(intent);
}
private void innitializeUIComponents()
{
    optionslist=getListView();
    optionslist.setOnItemClickListener(this);
}

private class RefreshArrayFromInternet extends AsyncTask<String,Void,ArrayList<NewsItem>>
{

    @Override
    protected ArrayList<com.example.vidushi.NewsItem> doInBackground(
            String... params) {


        Log.v("Thread started","parsing thread has started!!!");
        final ArrayList<NewsItem> newsList=new ArrayList<NewsItem>();
        try
        {
            URL urlexec=new URL(params[0]);
            URLConnection connection=urlexec.openConnection();
            InputStream input=connection.getInputStream();
            SAXParserFactory factory=SAXParserFactory.newInstance();
            SAXParser parser=factory.newSAXParser();

            parser.parse(input,new DefaultHandler(){

                boolean itemTagStarted=false;
                String currentTag="";           
                StringBuffer buffer;
                NewsItem item=null;
                @Override
                public void startDocument() throws SAXException {
                    Log.v("parsing started!!!","parsing started!!!");

                }
                @Override
                public void startElement(String uri, String localName,String qName, Attributes attributes)
                throws SAXException {
                    currentTag=localName;
                    Log.v("in start elelmet", "in start elelmet");
                    if(qName.equals("Table"))
                    {
                        buffer=new StringBuffer();
                        itemTagStarted=true;

                        item=new NewsItem();
                    }

                }
                @Override
                public void characters(char[] ch, int start, int length)
                        throws SAXException {

                    if(itemTagStarted)
                    {
                        if(currentTag.equals("Cat_Name"))
                        {
                            item.setCatname(String.valueOf(ch,start,length));

                        }
                        if(currentTag.equals("Cat_id"))
                        {

                            item.setCatid(String.valueOf(ch,start,length));
                        }

                        if(currentTag.equals("Cat_Desc"))
                        {
                            buffer.append(String.valueOf(ch,start,length));

                        }
                    }
                }

                @Override
                public void endElement(String uri, String localName,
                        String qName) throws SAXException {
                    currentTag="";

                    if(qName.equals("Table"))
                    {
                        itemTagStarted=false;
                        newsList.add(item);

                    }
                    if(qName.equals("Cat_Desc"))
                    {
                        item.setCatdesc(buffer.toString());
                        Log.v("Description data",buffer.toString());

                    }
                }
                @Override
                public void endDocument() throws SAXException {
                    Log.v("parsing completed","parsing completed : array size : "+newsList.size());
                }

            });
        }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }

        return newsList;
    }

    @Override
    protected void onPostExecute(ArrayList<NewsItem> result) {
        super.onPostExecute(result);
        getArray=result;
        if(result.size()==0)
        {
            Toast.makeText(FirstActivity.this,"There is some problem with the internet connection or the specified url!!!",Toast.LENGTH_LONG).show();
        }
        String[] array=new String[result.size()];
        cat_desc=new String[result.size()];
        Log.v("resukt size",""+result.size());
        for(int i=0;i<result.size();i++)
        {
            array[i]=result.get(i).getCatname();

        }

        arrayadapter=new ArrayAdapter<String>(FirstActivity.this,android.R.layout.simple_list_item_1,array);
        optionslist.setAdapter(arrayadapter);

    }

}

Firstly please check url*http://mobileecommerce.site247365.com/admin/catdata.xml in* google chrome. I am facing two problems 1. For second cat_desc from xml having cat_name E n I Sept not showing on webview .I think it is because in its cat_desc contains % sign on first line in table style tag <"table style="border-collapse:collapse;width :100%;">How to ignore % sign?

2.Second problem is that, from last thrid tag with cat_name Handouts creating problem while parsing it cat_desc.It will not parse completely, its last three lines are not parsed .I will check it in log also,but last three lines are not paresd.Why is it so ?For other cat_desc are parsed very well and well working on webview.

public class FirstActivity extends ListActivity implements OnItemClickListener {
/** called when the activity is first created. */

String[] cat_name=null;
String[] cat_desc=null;
ListView optionslist=null;
NewsListAdapter adapter=null;
ArrayList<NewsItem> getArray=null;
ArrayAdapter<String> arrayadapter=null;
HashMap<String, String> hashamp=null;



public static final String url="http://mobileecommerce.site247365.com/admin/catdata.xml";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    innitializeUIComponents();
    new RefreshArrayFromInternet().execute(url);


}

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

    Log.v("in position", ""+position);

    String str=new String(getArray.get(position).getCatdesc());
    Log.v("on item click desc", str);
    Intent intent=new Intent(FirstActivity.this, WebviewActivity.class);
    intent.putExtra("str",str);
    startActivity(intent);
}
private void innitializeUIComponents()
{
    optionslist=getListView();
    optionslist.setOnItemClickListener(this);
}

private class RefreshArrayFromInternet extends AsyncTask<String,Void,ArrayList<NewsItem>>
{

    @Override
    protected ArrayList<com.example.vidushi.NewsItem> doInBackground(
            String... params) {


        Log.v("Thread started","parsing thread has started!!!");
        final ArrayList<NewsItem> newsList=new ArrayList<NewsItem>();
        try
        {
            URL urlexec=new URL(params[0]);
            URLConnection connection=urlexec.openConnection();
            InputStream input=connection.getInputStream();
            SAXParserFactory factory=SAXParserFactory.newInstance();
            SAXParser parser=factory.newSAXParser();

            parser.parse(input,new DefaultHandler(){

                boolean itemTagStarted=false;
                String currentTag="";           
                StringBuffer buffer;
                NewsItem item=null;
                @Override
                public void startDocument() throws SAXException {
                    Log.v("parsing started!!!","parsing started!!!");

                }
                @Override
                public void startElement(String uri, String localName,String qName, Attributes attributes)
                throws SAXException {
                    currentTag=localName;
                    Log.v("in start elelmet", "in start elelmet");
                    if(qName.equals("Table"))
                    {
                        buffer=new StringBuffer();
                        itemTagStarted=true;

                        item=new NewsItem();
                    }

                }
                @Override
                public void characters(char[] ch, int start, int length)
                        throws SAXException {

                    if(itemTagStarted)
                    {
                        if(currentTag.equals("Cat_Name"))
                        {
                            item.setCatname(String.valueOf(ch,start,length));

                        }
                        if(currentTag.equals("Cat_id"))
                        {

                            item.setCatid(String.valueOf(ch,start,length));
                        }

                        if(currentTag.equals("Cat_Desc"))
                        {
                            buffer.append(String.valueOf(ch,start,length));

                        }
                    }
                }

                @Override
                public void endElement(String uri, String localName,
                        String qName) throws SAXException {
                    currentTag="";

                    if(qName.equals("Table"))
                    {
                        itemTagStarted=false;
                        newsList.add(item);

                    }
                    if(qName.equals("Cat_Desc"))
                    {
                        item.setCatdesc(buffer.toString());
                        Log.v("Description data",buffer.toString());

                    }
                }
                @Override
                public void endDocument() throws SAXException {
                    Log.v("parsing completed","parsing completed : array size : "+newsList.size());
                }

            });
        }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }

        return newsList;
    }

    @Override
    protected void onPostExecute(ArrayList<NewsItem> result) {
        super.onPostExecute(result);
        getArray=result;
        if(result.size()==0)
        {
            Toast.makeText(FirstActivity.this,"There is some problem with the internet connection or the specified url!!!",Toast.LENGTH_LONG).show();
        }
        String[] array=new String[result.size()];
        cat_desc=new String[result.size()];
        Log.v("resukt size",""+result.size());
        for(int i=0;i<result.size();i++)
        {
            array[i]=result.get(i).getCatname();

        }

        arrayadapter=new ArrayAdapter<String>(FirstActivity.this,android.R.layout.simple_list_item_1,array);
        optionslist.setAdapter(arrayadapter);

    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2024-12-18 16:33:30

我已经去了这个 URl:-

http://mobileecommerce.site247365.com/admin/catdata.xml"

并发现你必须进行非常小的更改,使用 px 而不是 %.. 作为 webview 也不支持 %age 符号..
希望它有帮助..:)

I have gone this URl:-

http://mobileecommerce.site247365.com/admin/catdata.xml"

and find out that you have to make very small changes that use px instead of %.. as webview nor support %age symbol..
Hope it helps.. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文