如何解析android中的xml文件?

时间:2014-10-21 09:55:00

标签: android

我是android的初学者。你能告诉我如何在android中解析xm文件。我把xml文件名=“sample.xml”放在布局文件夹上。你能告诉我怎么从哪里开始? 我可以使用任何库来解析xml文件

<?xml version="1.0" encoding="UTF-8"?>
<rss>
<item>
    <id>1</id>
    <title>Guidliness</title>
    <desc>On the Internet usually the resume are send via e-mail to respective companies, but it is still important that you carry a copy along with you during your preliminary interview.</desc>
</item>
<item>
    <id>2</id>
    <title>Why do you Need a Resume?</title>
    <desc>A summary of your objectives,educational qualification,experience,skills relevant to the field of work you are going to enter.</desc>
</item>
<item>
    <id>3</id>
    <title>Basics of Writing a Resume</title>
                <subcategory>
                        <title>Basic Standards</title>+
                        <desc>Resume is what an employer looks at much before meeting you,it is the first interface you have with your employer.</desc>
               </subcategory>
               <subcategory>
                       <title>Stick of the Point</title>
                       <desc>Employers have a busy schedule, so don't expect them to read through a long resume.</desc>
               </subcategory>
               <subcategory>
                   <title>Words Count</title>
                   <desc>Use of language is extremely important; you need to sell yourself to an employer quickly and efficiently.</desc>
               </subcategory>
               <subcategory>
                   <title>Make the Most of your Experience</title>
                   <desc>Employers need to know what you have accomplished to have an idea of what you can do for them. Don't be vague.</desc>
               </subcategory>
               <subcategory>
                   <title>Honesty is a Good Policy</title>
                   <desc>Employers will feel more comfortable hiring you if they can verify your accomplishments.</desc>
               </subcategory>
               <subcategory>
                   <title>Double-Check for Mistakes</title>
                   <desc>Check your resume for correct grammar and spelling - evidence of good communication skills and attention to detail.</desc>
               </subcategory>
</item>
<item>
    <id>4</id>
    <title>15 Golden Steps</title>
    <desc>The thought of writing a resume scares almost anyone. It's difficult to know where to start or what to include.</desc>
</item>
<item>
    <id>5</id>
    <title>8 Red Flags</title>
    <desc>A Resume is your mirror reflection to a recruiter or prospective employer.</desc>
</item>

</rss>

现在我将sample.xml放在资产文件夹中......接下来要做什么?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    parseXmlFile();
}

private void parseXmlFile() {
    // TODO Auto-generated method stub



        try {
            InputStream tinstr = null;

            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setNamespaceAware(true);
            XmlPullParser parser = factory.newPullParser();
            AssetManager assetManager = getAssets();
            tinstr = assetManager.open("sample.xml");
           parser.setInput(new InputStreamReader(tinstr));
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

0 个答案:

没有答案
相关问题