# Xml

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Fields](https://developer.android.com/reference/android/util/Xml#lfields)\|[Methods](https://developer.android.com/reference/android/util/Xml#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/util/Xml#inhmethods)  

# Xml

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/util/Xml "View this page in Kotlin")\|Java

`
public


class
Xml
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.util.Xml |

<br />

*** ** * ** ***

XML utility methods.

## Summary

|                                                                                                                                          ### Fields                                                                                                                                           ||
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static `[String](https://developer.android.com/reference/java/lang/String) | [FEATURE_RELAXED](https://developer.android.com/reference/android/util/Xml#FEATURE_RELAXED) [XmlPullParser](https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser)"relaxed" feature name. |

|                                                                                                                                                                                                                                                                                                           ### Public methods                                                                                                                                                                                                                                                                                                           ||
|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet)     | ` `[asAttributeSet](https://developer.android.com/reference/android/util/Xml#asAttributeSet(org.xmlpull.v1.XmlPullParser))`(`[XmlPullParser](https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser)` parser) ` Return an AttributeSet interface for use with the given XmlPullParser.                                                                                                                                                                                                                                  |
| ` static `[Xml.Encoding](https://developer.android.com/reference/android/util/Xml.Encoding)     | ` `[findEncodingByName](https://developer.android.com/reference/android/util/Xml#findEncodingByName(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` encodingName) ` Finds an encoding by name.                                                                                                                                                                                                                                                                                               |
| ` static `[XmlPullParser](https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser) | ` `[newPullParser](https://developer.android.com/reference/android/util/Xml#newPullParser())`() ` Returns a new pull parser with namespace support.                                                                                                                                                                                                                                                                                                                                                                                   |
| ` static `[XmlSerializer](https://developer.android.com/reference/org/xmlpull/v1/XmlSerializer) | ` `[newSerializer](https://developer.android.com/reference/android/util/Xml#newSerializer())`() ` Creates a new xml serializer.                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` static void`                                                                                  | ` `[parse](https://developer.android.com/reference/android/util/Xml#parse(java.lang.String,%20org.xml.sax.ContentHandler))`(`[String](https://developer.android.com/reference/java/lang/String)` xml, `[ContentHandler](https://developer.android.com/reference/org/xml/sax/ContentHandler)` contentHandler) ` Parses the given xml string and fires events on the given SAX handler.                                                                                                                                                 |
| ` static void`                                                                                  | ` `[parse](https://developer.android.com/reference/android/util/Xml#parse(java.io.InputStream,%20android.util.Xml.Encoding,%20org.xml.sax.ContentHandler))`(`[InputStream](https://developer.android.com/reference/java/io/InputStream)` in, `[Xml.Encoding](https://developer.android.com/reference/android/util/Xml.Encoding)` encoding, `[ContentHandler](https://developer.android.com/reference/org/xml/sax/ContentHandler)` contentHandler) ` Parses xml from the given input stream and fires events on the given SAX handler. |
| ` static void`                                                                                  | ` `[parse](https://developer.android.com/reference/android/util/Xml#parse(java.io.Reader,%20org.xml.sax.ContentHandler))`(`[Reader](https://developer.android.com/reference/java/io/Reader)` in, `[ContentHandler](https://developer.android.com/reference/org/xml/sax/ContentHandler)` contentHandler) ` Parses xml from the given reader and fires events on the given SAX handler.                                                                                                                                                 |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Fields

### FEATURE_RELAXED

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String FEATURE_RELAXED
```

[XmlPullParser](https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser)"relaxed" feature name.

<br />

**See also:**

- [specification](http://xmlpull.org/v1/doc/features.html#relaxed)

## Public methods

### asAttributeSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static AttributeSet asAttributeSet (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.

<br />

|                                           Parameters                                            ||
|----------|---------------------------------------------------------------------------------------|
| `parser` | `XmlPullParser`: The existing parser for which you would like an AttributeSet. <br /> |

|                                                                                                         Returns                                                                                                          ||
|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet) | An AttributeSet you can use to retrieve the attribute values at each of the tags as the parser moves through its XML document. <br /> |

**See also:**

- [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet)  

### findEncodingByName

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Xml.Encoding findEncodingByName (String encodingName)
```

Finds an encoding by name. Returns UTF-8 if you pass`null`.

<br />

|           Parameters            ||
|----------------|-----------------|
| `encodingName` | `String` <br /> |

|                                          Returns                                          ||
|-----------------------------------------------------------------------------------|--------|
| [Xml.Encoding](https://developer.android.com/reference/android/util/Xml.Encoding) | <br /> |

|                                                     Throws                                                      ||
|--------------------------------------------------------------------------------------------------------------|---|
| [UnsupportedEncodingException](https://developer.android.com/reference/java/io/UnsupportedEncodingException) |   |

### newPullParser

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static XmlPullParser newPullParser ()
```

Returns a new pull parser with namespace support.

<br />

|                                            Returns                                            ||
|---------------------------------------------------------------------------------------|--------|
| [XmlPullParser](https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser) | <br /> |

### newSerializer

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static XmlSerializer newSerializer ()
```

Creates a new xml serializer.

<br />

|                                            Returns                                            ||
|---------------------------------------------------------------------------------------|--------|
| [XmlSerializer](https://developer.android.com/reference/org/xmlpull/v1/XmlSerializer) | <br /> |

### parse

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void parse (String xml, 
                ContentHandler contentHandler)
```

Parses the given xml string and fires events on the given SAX handler.

<br />

|                Parameters                 ||
|------------------|-------------------------|
| `xml`            | `String` <br />         |
| `contentHandler` | `ContentHandler` <br /> |

|                                       Throws                                        ||
|----------------------------------------------------------------------------------|---|
| [SAXException](https://developer.android.com/reference/org/xml/sax/SAXException) |   |

### parse

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void parse (InputStream in, 
                Xml.Encoding encoding, 
                ContentHandler contentHandler)
```

Parses xml from the given input stream and fires events on the given SAX handler.

<br />

|                Parameters                 ||
|------------------|-------------------------|
| `in`             | `InputStream` <br />    |
| `encoding`       | `Xml.Encoding` <br />   |
| `contentHandler` | `ContentHandler` <br /> |

|                                       Throws                                        ||
|----------------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException)       |   |
| [SAXException](https://developer.android.com/reference/org/xml/sax/SAXException) |   |

### parse

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void parse (Reader in, 
                ContentHandler contentHandler)
```

Parses xml from the given reader and fires events on the given SAX handler.

<br />

|                Parameters                 ||
|------------------|-------------------------|
| `in`             | `Reader` <br />         |
| `contentHandler` | `ContentHandler` <br /> |

|                                       Throws                                        ||
|----------------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException)       |   |
| [SAXException](https://developer.android.com/reference/org/xml/sax/SAXException) |   |