Android XMl parsing Magic XStream: Parse aa.xml file under Asset folder in Android project

Source: Internet
Author: User

1. Download Tool XStream

Download Latest Version address: https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/

Import the jar package into your Android project when the download is complete

2. aa.xml file under Asset folder

<?xml version= "1.0" encoding= "UTF-8"?>
<product>
<name>jike</name>
<age>30</age>
</product>

3. Entity

 PackageCom.android10; Public classProduct {PrivateString name; PrivateString age;  PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicString getage () {returnAge ; }     Public voidsetage (String age) { This. Age =Age ; }}

4. Implementation code

 PackageCom.android10;Importjava.io.IOException;ImportJava.io.InputStream;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportCom.thoughtworks.xstream.XStream; Public classMainactivityextendsActivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //get the data flow in the resourceString fileName = "Aa.xml";//file name        Try{InputStream in=getresources (). Getassets (). open (FileName); XStream XStream=NewXStream (); Xstream.alias ("Product", product.class ); Product Product=(Product) xstream.fromxml (in); System.out.println ("SSS" + product.getname () +product.getage ()); } Catch(IOException e) {e.printstacktrace (); }       }}

5. Operation Result
SSS Jike30

6. Project

http://download.csdn.net/detail/yanzi2015/8797641

Android XMl parsing Magic XStream: Parse aa.xml file under Asset folder in Android project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.