Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to set the default namespace in Android XmlSerializer

How do I add a default namespace with no prefix using XMLSerializer.

I am using org.xmlpull.v1.XmlSerializer on Android.

 XmlSerializer xmlSerializer = Xml.newSerializer();
 xmlSerializer.startTag("efgh", "abcd");    

is giving <n0:abcd xmlns:n0="efgh">

but i want it to be

<abcd xmlns="efgh">
like image 710
Pragya Avatar asked Nov 04 '22 17:11

Pragya


2 Answers

I believe that's what the XmlSerializer.setPrefix(String prefix, String namespace) is for:

http://developer.android.com/reference/org/xmlpull/v1/XmlSerializer.html#setPrefix(java.lang.String, java.lang.String)

Have you tried using that?

It binds the prefix to the namespace. The call is valid for the next element including child elements.

NOTE: this method MUST be called directly before startTag() and if anything but startTag() or setPrefix() is called next there will be exception.

like image 164
Jeff Avatar answered Nov 15 '22 00:11

Jeff


Actually, the namespace without prefix can be seen as an attribute.

so this is code:

xmlSerializer.startTag(null, "abcd");
xmlSerializer.attribute(null, "xmlns", "efgh");
xmlSerializer.endTag(null, "abcd");
like image 35
ipcjs Avatar answered Nov 15 '22 01:11

ipcjs