FileDocCategorySizeDatePackage
Xml.javaAPI DocAndroid 5.1 API5849Thu Mar 12 22:22:10 GMT 2015android.util

Xml

public class Xml extends Object
XML utility methods.

Fields Summary
public static String
FEATURE_RELAXED
{@link org.xmlpull.v1.XmlPullParser} "relaxed" feature name.
Constructors Summary
public Xml()

hide

Methods Summary
public static AttributeSetasAttributeSet(org.xmlpull.v1.XmlPullParser parser)
Return an AttributeSet interface for use with the given XmlPullParser. If the given parser itself implements AttributeSet, that implementation is simply returned. Otherwise a wrapper class is instantiated on top of the XmlPullParser, as a proxy for retrieving its attributes, and returned to you.

param
parser The existing parser for which you would like an AttributeSet.
return
An AttributeSet you can use to retrieve the attribute values at each of the tags as the parser moves through its XML document.
see
AttributeSet

        return (parser instanceof AttributeSet)
                ? (AttributeSet) parser
                : new XmlPullAttributes(parser);
    
public static android.util.Xml$EncodingfindEncodingByName(java.lang.String encodingName)
Finds an encoding by name. Returns UTF-8 if you pass {@code null}.

        if (encodingName == null) {
            return Encoding.UTF_8;
        }

        for (Encoding encoding : Encoding.values()) {
            if (encoding.expatName.equalsIgnoreCase(encodingName))
                return encoding;
        }
        throw new UnsupportedEncodingException(encodingName);
    
public static org.xmlpull.v1.XmlPullParsernewPullParser()
Returns a new pull parser with namespace support.

        try {
            KXmlParser parser = new KXmlParser();
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            return parser;
        } catch (XmlPullParserException e) {
            throw new AssertionError();
        }
    
public static org.xmlpull.v1.XmlSerializernewSerializer()
Creates a new xml serializer.

        try {
            return XmlSerializerFactory.instance.newSerializer();
        } catch (XmlPullParserException e) {
            throw new AssertionError(e);
        }
    
public static voidparse(java.lang.String xml, org.xml.sax.ContentHandler contentHandler)
Parses the given xml string and fires events on the given SAX handler.


                      
          
              
        try {
            XMLReader reader = new ExpatReader();
            reader.setContentHandler(contentHandler);
            reader.parse(new InputSource(new StringReader(xml)));
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    
public static voidparse(java.io.Reader in, org.xml.sax.ContentHandler contentHandler)
Parses xml from the given reader and fires events on the given SAX handler.

        XMLReader reader = new ExpatReader();
        reader.setContentHandler(contentHandler);
        reader.parse(new InputSource(in));
    
public static voidparse(java.io.InputStream in, android.util.Xml$Encoding encoding, org.xml.sax.ContentHandler contentHandler)
Parses xml from the given input stream and fires events on the given SAX handler.

        XMLReader reader = new ExpatReader();
        reader.setContentHandler(contentHandler);
        InputSource source = new InputSource(in);
        source.setEncoding(encoding.expatName);
        reader.parse(source);