XML file parsing "Android 7"--pull parsing

Source: Internet
Author: User
Tags gettext

Pull parsing

Pull-easier to use than DOM and sax

Pull parsing related classes/interfaces

Parsing xml--Package: ORG.XMLPULL.VL

    1. Xmlpullfactory Class: Parser factory class for creating parser objects
    2. Xmlpullparser class: Parser class for parsing XML documents
Pull Analytic correlation method

Event codes and methods

Type

Describe

public static final int start_document

Constant

Document Start

public static final int End_ DOCUMENT

Constant

End of document

public static final int Start_tag

Constant

Element start

public static final int End_tag

Ordinary

Element end

public static final int Commet

Ordinary

Comments

public static final int TEXT

Ordinary

Element content

public abstract int Getattributecount ()

Ordinary

Gets the number of attributes of the element

Public abstract String getattributename (int index)

Ordinary

Gets the property name of the specified index

Public abstract String getattributevalue (int index)

Ordinary

Gets the property contents of the specified index

public abstract int Geteventtype ()

Ordinary

Get event code

Public abstract String GetName ()

Ordinary

Gets the name of the current element

Public abstract String GetText ()

Ordinary

Gets the contents of the current element

public abstract int Next ()

Ordinary

Get the next Action event code

public abstract int Nexttag ()

Ordinary

Get the next marker

Public abstract String Nexttext ()

Ordinary

Gets the next text of the current node

public abstract void SetInput (

InputStream InputStream, String inputencoding)

Ordinary

Set input byte stream for data

public abstract void SetInput (Reader in)

Ordinary

Set the input character stream of the data

Pull parsing Code
1 //Creating a Parser object2Xmlpullparser parser =xmlpullparserfactory.newinstance (). Newpullparser ();3 //Read Resource file4InputStream is =getresources (). Openrawresource (r.raw.xml file name);5Parser.setinput (IS, "utf-8");//setting the input stream object and encoding format6 intType = Parser.geteventtype ();//Get Event Type7  while(Type! =xmlpullparser.end_document) {8String tagName = Parser.getname ();//Get label name9     if("Specify label name". Equals (TagName) &&type==Xmlpullparser.start_tag) {Ten Parser.next (); OneString value = Parser.gettext ();//Get label Content AToast.maketext (Pull0. This, value,.). Show ();//Informational Alert Box -      } -     //Execute next label theType =Parser.next (); -}
Pull parsing

XML file parsing "Android 7"--pull parsing

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.