Java tutorial
//package com.java2s; /* * Copyright (C) 2012 4th Line GmbH, Switzerland * * The contents of this file are subject to the terms of either the GNU * Lesser General Public License Version 2 or later ("LGPL") or the * Common Development and Distribution License Version 1 or later * ("CDDL") (collectively, the "License"). You may not use this file * except in compliance with the License. See LICENSE.txt for more * information. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; public class Main { static XmlPullParserFactory xmlPullParserFactory; static public XmlPullParser createParser(String xml) throws XmlPullParserException { XmlPullParser xpp = createParser(); InputStream is; try { is = new ByteArrayInputStream(xml.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new XmlPullParserException("UTF-8: unsupported encoding"); } xpp.setInput(is, "UTF-8"); return xpp; } static public XmlPullParser createParser() throws XmlPullParserException { if (xmlPullParserFactory == null) throw new XmlPullParserException("no XML Pull parser factory"); return xmlPullParserFactory.newPullParser(); } }