android - How to use non-standard variable names in Java for producing XML tags? -



android - How to use non-standard variable names in Java for producing XML tags? -

i trying write androidmanifest.xml file programmatically through java using jaxb. problem comes while defining attributes, follow string:string naming convention. example, manifest element defined thus:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="string" android:shareduserid="string" android:shareduserlabel="string resource" android:versioncode="integer" android:versionname="string" android:installlocation=["auto" | "internalonly" | "preferexternal"] > . . . </manifest>

while doing java, cannot annotate attributes because xmlns:android etc not valid java variables.

what best way overcome this, while still using jaxb, , not resorting stringbuilder technique generating xml?

here illustration javadoc of javax.xml.bind.annotation.xmlelement:

@xmlelement(name="item-price") public java.math.bigdecimal price;

the name parameter you'll see in xml.

but android: namespace prefix , should appear according namespace definition, parameter of namespace:

@xmlelement(name="item-price", namespace="http://schemas.android.com/apk/res/android") public java.math.bigdecimal price;

after marshalling, you'll see "ns1:" in place of android:, that's ok.

easiest way annotated java code: write (or find) xml schema , run through xjc. works time - ;-)

java android xml jaxb

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -