自定义XML文件的Android布局 [英] Android placement of custom XML files
问题描述
我有安排,像这样一个大的XML文件:
I have a large XML file which is arranged like so:
<$c$c><item><title>...</title><link>...</link></item>$c$c>
如何使用解析(新的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文件的Android布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!