自定义XML文件的Andr​​oid布局 [英] Android placement of custom XML files

查看:110
本文介绍了自定义XML文件的Andr​​oid布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有安排,像这样一个大的XML文件:

I have a large XML file which is arranged like so:

<$c$c><item><title>...</title><link>...</link></item>

如何使用解析(新的InputSource()); 如果它存储在我的项目目录中,并在那里我把XML文件指向这个XML文件?

How can I use parse(new InputSource()); to point to this XML file if it's stored within my project directory and where do I put the XML file?

推荐答案

最好的答案忽略你的解析(新的InputSource())请求。把它放在 RES / XML / ,并使用 getResources()。的getXML()。这给你一个 XmlPullParser 上的数据。这里最大的好处是,你的XML有所$ P $在编译步骤P-解析,因此解析快十倍左右在运行时比正常的XML解析器。

The best answer ignores your parse(new InputSource()) request. Put it in res/xml/ and use getResources().getXml(). This gives you an XmlPullParser on your data. The big advantage here is that your XML is somewhat pre-parsed during the compile step, and so parsing is about ten times faster at runtime than with normal XML parsers.

如果这是绝对肯定有使用DOM和SAX,把它放在 RES /生/ ,然后用 getResources()。openRawResource() 来获得的InputStream ,您可以在包装一个的InputSource

If it absolutely positively has to use DOM or SAX, put it in res/raw/, then use getResources().openRawResource() to get an InputStream, which you can wrap in an InputSource.

这篇关于自定义XML文件的Andr​​oid布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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