Android provides us with a series of XML-related methods, which are located in the Android. util. xml class. The main method is as follows:
Asattributeset () method:
Load the content in XML into an attributeset and store it as a key-value pair. It is generally used to describe a graphical representation. Similar to labels such as Android: text.
There is no better explanation for other methods.
Paste the source code of the XML class here, and the implementation process is clear at a glance,
/* <Br/> * copyright (c) 2007 the android open source project <br/> * licensed under the Apache license, version 2.0 (the "License"); <br/> * you may not use this file except T in compliance with the license. <br/> * You may obtain a copy of the license at <br/> * http://www.apache.org/licenses/LICENSE-2.0 <br/> * unless required by applicable law or agreed to in writing, soft Ware <br/> * distributed under the license is distributed on an "as is" basis, <br/> * Without warranties or conditions of any kind, either express or implied. <br/> * See the license for the specific language governing permissions and <br/> * limitations under the license. <br/> */</P> <p> package android. util; </P> <p> Import Org. XML. sax. contenthandler; <br/> Import Org. XML. sax. inputsource; <br/> impor T Org. XML. sax. saxexception; <br/> Import Org. XML. sax. xmlreader; <br/> Import Org. xmlpull. v1.xmlpullparser; <br/> Import Org. xmlpull. v1.xmlserializer; <br/> Import Org. xmlpull. v1.xmlpullparserexception; <br/> Import Org. xmlpull. v1.xmlpullparserfactory; </P> <p> Import Java. io. ioexception; <br/> Import Java. io. inputstream; <br/> Import Java. io. reader; <br/> Import Java. io. stringreader; <br/> Import Java. io. unsu Pportedencodingexception; </P> <p> Import Org. apache. harmony. XML. expatpullparser; <br/> Import Org. apache. harmony. XML. expatreader; </P> <p>/** <br/> * XML utility methods. <br/> */<br/> public class XML {</P> <p>/** <br/> * {@ link Org. xmlpull. v1.xmlpullparser} "relaxed" feature name. <br/> * @ See <a href = "http://xmlpull.org/v1/doc/features.html#relaxed" mce_href = "http://xmlpull.org/v1/doc/featur Es.html # relaxed "> <br/> * specification </a> <br/> */<br/> Public static string feature_relaxed = expatpullparser. feature_relaxed; </P> <p>/** <br/> * parses the given XML string and fires events on the given sax handler. <br/> */<br/> Public static void parse (string XML, contenthandler) <br/> throws saxexception {<br/> try {<br/> xmlreader reader = new expatreader (); <br/> Reader. Setcontenthandler (contenthandler); <br/> reader. parse (New inputsource (New stringreader (XML); <br/>}< br/> catch (ioexception e) {<br/> throw new assertionerror (E ); <br/>}</P> <p>/** <br/> * parses XML from the given reader and fires events on the given sax <br /> * Handler. <br/> */<br/> Public static void parse (Reader in, contenthandler) <br/> throws ioexception, Saxe Xception {<br/> xmlreader reader = new expatreader (); <br/> reader. setcontenthandler (contenthandler); <br/> reader. parse (New inputsource (in )); <br/>}</P> <p>/** <br/> * parses XML from the given input stream and fires events on the given sax <br/> * Handler. <br/> */<br/> Public static void parse (inputstream in, encoding, <br/> contenthandler) throws ioexception, saxexce Ption {<br/> try {<br/> xmlreader reader = new expatreader (); <br/> reader. setcontenthandler (contenthandler); <br/> inputsource source = new inputsource (in); <br/> source. setencoding (encoding. expatname); <br/> reader. parse (source); <br/>}catch (ioexception e) {<br/> throw new assertionerror (E ); <br/>}</P> <p>/** <br/> * creates a new pull parser with namespace support. <br/> * <br/> * <P> <B> Note: </B> This is actually slower than the SAX Parser, and it's not <br/> * fully implemented. if you need a fast, mostly implemented pull parser, <br/> * use this. if you need a complete implementation, use kxml. <br/> */<br/> Public static xmlpullparser newpullparser () {<br/> expatpullparser parser = new expatpullparser (); <br/> parser. setnamespaceprocessingenabled (true); <br/> return Parser; <br/>}</P> <p>/** <br/> * creates a new XML serializer. <br/> */<br/> Public static xmlserializer newserializer () {<br/> try {<br/> return xmlserializerfactory. instance. newserializer (); <br/>} catch (xmlpullparserexception e) {<br/> throw new assertionerror (E ); <br/>}</P> <p>/** factory for XML serializers. initialized on demand. */<br/> static class xmlserializerfactory {< Br/> static final string type <br/> = "org. kxml2.io. kxmlparser, org. kxml2.io. kxmlserializer "; <br/> static final xmlpullparserfactory instance; <br/> static {<br/> try {<br/> instance = xmlpullparserfactory. newinstance (type, null); <br/>} catch (xmlpullparserexception e) {<br/> throw new assertionerror (E ); <br/>}</P> <p>/** <br/> * supported character encodings. <br/> */<br/> Public Enum encoding {</P> <p> us_ascii ("US-ASCII"), <br/> utf_8 ("UTF-8"), <br/> utf_16 ("UTF-16 "), <br/> iso_8859_1 ("ISO-8859-1"); </P> <p> final string expatname; </P> <p> encoding (string expatname) {<br/> This. expatname = expatname; <br/>}</P> <p>/** <br/> * finds an encoding by name. returns UTF-8 if you pass {@ Code null }. <br/> */<br/> Public static encoding findencodingbyname (string en Codingname) <br/> throws unsupportedencodingexception {<br/> If (encodingname = NULL) {<br/> return encoding. utf_8; <br/>}</P> <p> for (encoding: encoding. values () {<br/> If (encoding. expatname. equalsignorecase (encodingname) <br/> return encoding; <br/>}< br/> throw new unsupportedencodingexception (encodingname ); <br/>}</P> <p>/** <br/> * return an attributeset interface for use With the given xmlpullparser. <br/> * If the given parser itself implements attributeset, that implementation <br/> * is simply returned. otherwise a Wrapper class is <br/> * instantiated on top of the xmlpullparser, as a proxy for retrieving its <br/> * attributes, and returned to you. <br/> * @ Param parser the existing Parser for which you wowould like an <br/> * attributeset. <br/> * <br/> * @ Return an attributeset you can use to retrieve the <br/> * attribute values at each of the tags as the parser moves <br/> * through its XML document. <br/> * @ see attributeset <br/> */<br/> Public static attributeset asattributeset (xmlpullparser parser) {<br/> return (parser instanceof attributeset) <br/>? (Attributeset) parser <br/>: New xmlpullattributes (parser); <br/>}< br/>