Xpp3 is mxp1-a very fast XML Parser

Source: Internet
Author: User

Alfresco uses a large number of third-party tools or projects. This article lists and describes these projects and tools to help you use and analyze alfresco.

1. xpp3 is also called mxp1

Xpp -- XML pull parser, xpp3 is a very fast XML Parser and xpp of the third edition. Xpp2 is the second version of xpp. Xpp3 is the successor of xpp2 and implements the xmlpull API defined by the http://www.xmlpull.org. Xpp3 can only be used to parse XML, but does not support adding a node tree. According to a comparative test, xpp3 is six times faster than dom4j, that is, 1/6 of the time is used.
Xpp3 uses the Apache 1.1 variant license protocol.
Http://www.extreme.indiana.edu/xgws/xsoap/xpp/

Http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/index.html

Http://mvnrepository.com/artifact/xpp3/xpp3

Http://www.xmlpull.org/

Example: http://www.xmlpull.org/v1/download/unpacked/doc/quick_intro.html

Myxmlpull. Java

================

import java.io.FileReader;import java.io.IOException;import java.io.StringReader;import org.xmlpull.v1.XmlPullParser;import org.xmlpull.v1.XmlPullParserException;import org.xmlpull.v1.XmlPullParserFactory;/** * An example of an application that uses XMLPULL V1 API. * * @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a> */public class MyXmlPullApp{    public final static String SAMPLE_XML =        "<?xml version=\"1.0\"?>\n"+        "\n"+        "<poem xmlns=\"http://www.megginson.com/ns/exp/poetry\">\n"+        "<title>Roses are Red</title>\n"+        "<l>Roses are red,</l>\n"+        "<l>Violets are blue;</l>\n"+        "<l>Sugar is sweet,</l>\n"+        "<l>And I love you.</l>\n"+        "</poem>";    public static void main (String args[])        throws XmlPullParserException, IOException    {        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();        factory.setNamespaceAware(true);        XmlPullParser xpp = factory.newPullParser();        System.out.println("parser implementation class is "+xpp.getClass());        MyXmlPullApp app = new MyXmlPullApp();        if(args.length == 0) {            System.out.println("Parsing simple sample XML");//:\n"+ SAMPLE_XML);            xpp.setInput( new StringReader( SAMPLE_XML ) );            app.processDocument(xpp);        } else {            for (int i = 0; i < args.length; i++) {                System.out.println("Parsing file: "+args[i]);                xpp.setInput ( new FileReader ( args [i] ) );                app.processDocument(xpp);            }        }    }    public void processDocument(XmlPullParser xpp)        throws XmlPullParserException, IOException    {        int eventType = xpp.getEventType();        do {            if(eventType == xpp.START_DOCUMENT) {                System.out.println("Start document");            } else if(eventType == xpp.END_DOCUMENT) {                System.out.println("End document");            } else if(eventType == xpp.START_TAG) {                processStartElement(xpp);            } else if(eventType == xpp.END_TAG) {                processEndElement(xpp);            } else if(eventType == xpp.TEXT) {                processText(xpp);            }            eventType = xpp.next();        } while (eventType != xpp.END_DOCUMENT);    }    public void processStartElement (XmlPullParser xpp)    {        String name = xpp.getName();        String uri = xpp.getNamespace();        if ("".equals (uri)) {            System.out.println("Start element: " + name);        } else {            System.out.println("Start element: {" + uri + "}" + name);        }    }    public void processEndElement (XmlPullParser xpp)    {        String name = xpp.getName();        String uri = xpp.getNamespace();        if ("".equals (uri))            System.out.println("End element: " + name);        else            System.out.println("End element:   {" + uri + "}" + name);    }    int holderForStartAndLength[] = new int[2];    public void processText (XmlPullParser xpp) throws XmlPullParserException    {        char ch[] = xpp.getTextCharacters(holderForStartAndLength);        int start = holderForStartAndLength[0];        int length = holderForStartAndLength[1];        System.out.print("Characters:    \"");        for (int i = start; i < start + length; i++) {            switch (ch[i]) {                case '\\':                    System.out.print("\\\\");                    break;                case '"':                    System.out.print("\\\"");                    break;                case '\n':                    System.out.print("\\n");                    break;                case '\r':                    System.out.print("\\r");                    break;                case '\t':                    System.out.print("\\t");                    break;                default:                    System.out.print(ch[i]);                    break;            }        }        System.out.print("\"\n");    }}

JAVA Source: http://download.csdn.net/detail/teamlet/4399658

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.