Showing posts with label XmlPullParserFactory. Show all posts
Showing posts with label XmlPullParserFactory. Show all posts

How to Have XmlPullParserFactory Provide Support for XML Namesspaces

public void setNamespaceAware (boolean awareness) was added in API level 1
Specifies that the parser produced by this factory will provide support for XML namespaces. By default the value of this is set to false.
Parameters: awareness - true if the parser produced by this code will provide support for XML namespaces; false otherwise.

1. Create a new Instance of XmlPullParserFactory named myXmlPullParserFactory.

2. In the MainActivity.java file, add the below line to the onCreate method. This indicates that myXmlPullParserFactory will provide support for XML namespaces. 

myXmlPullParserFactory.setNamespaceAware(true);

3. Compile and run!

Resources:
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParserFactory.html#setNamespaceAware(boolean)


How to Declare a new XmlPullParserFactory object

XmlPullParserFactory was added in API Level 1
This class is used to create implementations of XML Pull Parser defined in XMPULL V1 API. The name of actual factory class will be determined based on several parameters. It works similar to JAXP but tailored to work in J2ME environments (no access to system properties or file system) so name of parser class factory to use and its class used for loading (no class loader - on J2ME no access to context class loaders) must be passed explicitly. If no name of parser factory was passed (or is null) it will try to find name by searching in CLASSPATH for META-INF/services/org.xmlpull.v1.XmlPullParserFactory resource that should contain a comma separated list of class names of factories or parsers to try (in order from left to the right). If none found, it will throw an exception.

1. In the MainActivity.java file, add the below line to the imports section.

import org.xmlpull.v1.XmlPullParserFactory;

2. Add the below line to the onCreate method. This will declare a new XmlPullParserFactory object named myXmlPullParserFactory. 

XmlPullParserFactory myXmlPullParserFactory;

3. Compile and run!

Next Recommended Article: How to Create a new Instance of XmlPullParserFactory

Resources:
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParserFactory.html