SAXParser的本地XML文件 [英] SAXParser with local XML file
问题描述
我读过几个主题如何读取本地XML文件中。
他们中的大多数都使用openRawResource()。但是它更慢相比,约束getXML()。
我想用的getXML我的项目,它有什么办法可以使用的getXML与XMLReader.parse(),为的SAX InputSource不接受XmlResourceParser作为参数。</ P>
编辑:顺便说一句,什么时候通过StartElement的endElement会叫什么名字?后XMLReader.parse正确的是什么呢?是否有可能从顶部重新解析,当我读到的属性有一定的价值呢?
非常感谢你。
您可以使用它(假设你保持你的XML资产文件夹中)
的InputStream响应= context.getAssets()开(your.xml)。
然后
Xml.parse(响应,Xml.Encoding.UTF_8,rootElement.getContentHandler());
I've read several topic on how to read local XML file.
Most of them are using openRawResource(). However it's much more slower compared to getXML().
I wanted to use getXML for my project, it's there any way to use getXML with XMLReader.parse(), as SAX InputSource does not accept XmlResourceParser as parameter.
Edit: btw, when do the startElement endElement will be called? Is it right after XMLReader.parse? Is it possible to restart the parsing from the top when I read a certain value of attributes?
Thank you very much
You can use it(assume that you are keeping your xml in assets folder)
InputStream response=context.getAssets().open("your.xml");
and then
Xml.parse(response, Xml.Encoding.UTF_8,rootElement.getContentHandler());
这篇关于SAXParser的本地XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!