1

I want to create Element for android permission

<uses-permission android:name="android.permission.INTERNET"/>

I try something like this:

Element el = new Element("uses-permission", "android:name", "android.permission.);
rootNode.addContent(el);

This throws exception

Exception in thread "main" org.jdom2.IllegalNameException: The name "android:name" is  not legal for JDOM/XML Namespace prefixs: XML name 'android:name' cannot contain the character ":".

Thanks for the advice.

1 Answers1

1

You need to specify the android namespace prefix on the root element of the XML document, then add the name attribute using the same namespace.

Namespace ns = Namespace.getNamespace( "android" );
Element e = new Element( "uses-permission", ns );
e.setAttribute( "name", "android.permission.INTERNET", ns );
stridecolossus
  • 1,449
  • 10
  • 24
  • Thanks, your respond was very helpful. I need this one `Namespace ns = rootNode.getNamespace("android"); Element e = new Element("uses-permission"); e.setAttribute("name", "android.permission." + permissionForInsert, ns);` – user3583376 Apr 29 '14 at 13:35