省略“&"的Android XML解析 [英] Android XML Parsing omitting "&"

查看:88
本文介绍了省略“&"的Android XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题再次出在,尽管我已经在代码中成功实现了SAX解析器……但是它的表现却异常.在&之后,它会跳过肠子并转到下一个条目.只是想知道这是否是SAX解析器的典型工作,还是我错误地实现了它??

The problem again is that though i have succesfully implemented a SAX parser in my code... It is behaving wierdly. It jus skips the enteries after the & and goes to the next entry. Just wanted to know whether this is the typical working of SAX parser or m i implementing it wrongly???

我已经实现了org.xml.sax.ContentHandler并在内部提供了以下代码...

I have implemented org.xml.sax.ContentHandler and have provided the following coding inside...

`

public void characters(char[] ch, int start, int length)
         {
             if(lastName.equals("id"))
             {
                 String id = String.copyValueOf(ch, start, length);
                 CustomList.idvector.add(id);
             }
             else if(lastName.equals("subcategory"))
             {
                String subcategory = String.copyValueOf(ch, start, length);
                 CustomList.subcategoryvector.add(subcategory);
             }
             else if(lastName.equals("photo"))
             {
                 String photo = String.copyValueOf(ch, start, length);
                 CustomList.photovector.add(photo);
             }
             else if(lastName.equals("name"))
             {
                 String name = String.copyValueOf(ch, start, length);
                 CustomList.namevector.add(name);
             }
         }

`

有些带有标签、、、 ...和m的元素会将这些信息纳入向量...这是正确的吗?

There are elements with tags ,,,... and m taking those info into a vector... is this correct???

现在再次出现的问题是,我无法解析特殊字符,例如"$",这样……有什么办法可以捕捉到这些字符?

Now again problem is that i cant parse special character like "$" and such... is there any way we can catch these characters??

推荐答案

不太确切地知道您所看到的内容,如果这不能帮助您解决问题,也许您可​​以提供一些示例输入和输出.

Not quite sure exactly what you're seeing, if this doesn't help deal with your problem maybe you could provide some sample input and output.

&是XML实体引用,表示&.

& is an XML entity reference and means &.

默认情况下,SAX将为您进行转换,因此,如果您的源XML表示hello&goodbye,您应该会看到hello&goodbye.

By default, SAX will do the conversion for you, so if your source XML says hello&goodbye you should see hello&goodbye.

也可能是由于实体引用,SAX正在中断对characters()方法的调用.您可能需要将对characters()的多个调用串联在一起,同时仍在同一标签内.

It may also be that SAX is breaking up the calls to the characters() method because of the entity reference. You may need to concatenate multiple calls to characters() together whilst still inside the same tag.

这篇关于省略“&"的Android XML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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