How to read & update xml file in android? - android

It may be a basic question but I am new to xml parsing, that's why I need some help. So the question is: I just want to read a xml file from res folder in android and update the values for some tag in that file; so, howcan it be done? Please help me out. Following is the xml file and I want to update the value of the tag "event filter" which is currently having value "moneyback". I had searched many threads but still I am unable to solve the issue.
<?xml version="1.0" encoding="UTF-8"?>
<HawkAgentPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<config>
<installedappthreadtime>10</installedappthreadtime>
<runningprocessthreadtime>10</runningprocessthreadtime>
<networkconnectionsthreadtime>10</networkconnectionsthreadtime>
</config>
<policy name="DayCapturePolicy" type="capture">
<starttime>9:00:00 AM</starttime>
<endtime>9:00:00 PM</endtime>
<event name="NEW_APP_INSTALLED">
<eventFilter selectedAppName="Moneyback"/>
<eventParam>selectedAppName</eventParam>
<eventParam>selectedAppVersion</eventParam>
<eventParam>appPackageName</eventParam>
<eventParam>appDirPath</eventParam>
</event>
<event name="NEW_PROCESS_STARTED">
<eventFilter runningAppName="Moneyback" />
<eventParam>runningAppName</eventParam>
<eventParam>runningAppProcessId</eventParam>
<eventParam>runningProcessName</eventParam>
</event>
<event name="INBOUND_CONNECTION">
<eventFilter netAppName="Moneyback"/>
<eventParam>netProtocol</eventParam>
<eventParam>netRemoteIP</eventParam>
<eventParam>netRemotePort</eventParam>
<eventParam>netStatus</eventParam>
<eventParam>netUID</eventParam>
<eventParam>netAppName</eventParam>
</event>
<event name="OUTBOUND_CONNECTION">
<eventFilter netAppName="Moneyback"/>
<eventParam>netProtocol</eventParam>
<eventParam>netRemoteIP</eventParam>
<eventParam>netRemotePort</eventParam>
<eventParam>netStatus</eventParam>
<eventParam>netUID</eventParam>
<eventParam>netAppName</eventParam>
</event>
</policy>
</HawkAgentPolicy>

Related

Tasker: edit settings for android app in xml file

I use tasker to edit setting from google maps. I have a xml file with following content.
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
...
<set name="nontransit_route_options$105347668285068041666">
<string>AVOID_TOLLS</string>
<string>AVOID_HIGHWAYS</string>
<string>AVOID_FERRIES</string>
</set>
...
</map>
Settings in UI
Each togglebutton add by activating a line with
<string>AVOID_*</string>.
And remove the line by deactivating.
So now I want to add or remove a line with tasker. For example %avoid_highway is true so add line in set-tag.
Step 1
First I need to read the set-tag like (perl regex):
/<set.*name="nontransit_route_options.*(<\/set>|\/>)/gsu
I ignore the number cause I don't know what it means.
Step 2
I build my own set-tag and add the tag lines. Then replace the set-tag and save it.
One problem more: If all togglebuttons are deactivated the tag is self closed:
<set name="nontransit_route_options$105347668285068041666" />

Freemarker placeholder in html file in Android IDE Template Format

I'm working with android studio to develop Android app. I'm working on the creation of a template to use in my applications. I have read the Android IDE Template Format specification and so i start my personal template starting from Dummy template.
I have a .ftl file with the following line of code:
<applicationGestureListenerClazz>${projectPackageName}.listeners.${projectShortName}GestureListener</applicationGestureListenerClazz>
When i execute the template i obtain the following line:
<applicationGestureListenerClazz>org.abubu.dummy.listeners.DummyGestureListener
</applicationGestureListenerClazz>
The variables are correctly defined (in other file they work fine). I don't known why.. it add a CRLF after this line.
Anybody has analogue problem?
UPDATE
I discover that the problem is linked to extension of output file. For example. I have a file **license_key_strings.txt.ftl* that contains:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di ${projectPackageName}.key-->
<string name="publicKey">${licenseKey}</string>
</resources>
<!-- fine -->
If i use it to create a xml file
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.xml"/>
I obtain this file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">
MIIBIjANBgkqhkiG9w0BAQ
</string>
</resources>
But the output filename ends with .txt
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.txt"/>
The final output become:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">MIIBIjANBgkqhkiG9w0BAQ</string>
</resources>
<!-- fine -->
I'm working with Android Studio 1.4

android: how to make #String/name work in res folder?

Android
I got the following code in an xml file in the res folder.
<?xml version="1.0" encoding="utf-8"?>
<designs>
<design name="2Parts">
<module id="0" posY="0" posX="0" height="0.5" width="1" capHeight="0.2"></module>
<module id="1" posY="0.5" posX="0" height="0.66" width="1" capHeight="0.2"></module>
</design>
Instead of using height="0.5" I'd like to have a variable from the Strings like height="#string/height_one" . But somehow I can't use the #string function.
Is that possible?
Is there an easy way to calculate with the strings in other files?
For an example :
height="#string/height_one * 0.5" ?
Looking forward to your answers

Android Xml database

Hi I'm having a problem with my xml file for my android app. It's spitting out this error
error: invalid start tag Category . . . here is the source code.
<?xml version="1.0" encoding="UTF-8" ?>
<Category>
<destination id="1" main_cat="Hotel">
<timestamp></timestamp>
<business_name><![CDATA[ Sugarland Hotel ]]></business_name>
<alias><![CDATA[ Sugarland Hotel ]]></alias>
<address><![CDATA[ Araneta Avenue ]]></address>
<city><![CDATA[ Bacolod ]]></city>
<subcategory><![CDATA[ Hotel ]]></subcategory>
<cuisine><![CDATA[ Italian,Asian ]]></cuisine>
<budget> </budget>
<features> </features>
<working_days><![CDATA[ Everyday ]]></working_days>
<opening><![CDATA[ 24/7 ]]></opening>
<ending> </ending>
<contact><![CDATA[ (34)435-2690 , (34)435-2780 ]]></contact>
<fax><![CDATA[ (34)435-2645 ]]></fax>
<email><![CDATA[ rooms#sugarlandhotel.com ]]></email>
<website><![CDATA[ www.sugarlandhotel.com ]]></website>
<payment_type><![CDATA[ cash,credit card,master card, visa ]]></payment_type>
<lat><![CDATA[ 10.6524789N ]]></lat>
<long><![CDATA[ 122.9372838E ]]></long>
<desc><![CDATA[ Experience a modern hacienda retreat that nurtures the charm and romance of old world plantation living. Extensively renovated beginning 2010, Sugarland hotel unvails a celebrated balance of nostalgia and contemporary style, Capturing its original southern elegence, luxury, and decadence. Machuca tiles form cool geometric patterns in the hallways. Hacienda hardwoord floors contrast modern furnishings and amenities in the dramatic suits. The sugarland lifestyle offers guests the finest sensory indulgences: signature hacienda service, soothing organic toiletries, heirloom recipes, and unmatched privacy and tranquility. ]]></desc>
<image> </image>
</destination>
</Category>
also i tried testing CDATA would i rather use it or go with xml schema. Thanks for the help in advance
Remove the whitespace in front of <?xml version="1.0" encoding="UTF-8" ?>. Nothing can appear before it.
Both IntelliJ and my browser say your XML is fine. There must be something else wrong.

res folder inside bin has gone empty,causing errors.How to fix?Something to do with options menu?

The res folder inside of bin is supposed to contain .dex,.apk and .ap_ i think.Mines gone empty somehow causing errors like not being able to access the layout resources.I have tried clean and build but it doesent seem to work.Just seem to create an empty res folder.So any idea how to fix this?
Thanks.
Ok my problem is with an xml file i'm creating inside of res/menu inorder to create an options menu:
options.xml:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/setmenu"
android:title="#string/settings"
android:icon="#android:drawable/ic_menu_preferences"></item>
<item
android:id="#+id/helpmenu"
android:title="#string/help"
androidLicon="#android:drawable/ic_menu_help"></item>
</menu>
Heres the error i am getting:
Description Resource Path Location Type
Unparsed aapt error(s)! Check the console for output. TriviaQuiz line 1 Android ADT Problem
Console Messages:
[2011-11-19 16:47:24 - TriviaQuiz] W/ResourceType( 4672): Bad XML block: header size 116 or total size 7602372 is larger than data size 0
[2011-11-19 16:47:24 - TriviaQuiz] H:\workspace\TriviaQuiz\res\menu\options.xml:5: error: Error parsing XML: unbound prefix
Any idea what it is.
I find that an error in one of my resources (usually a layout) causes this. Missing quotes or /> in particular are a good starting point - that's my personal blind spot and eclipse punishes it mercilessly!
As alextsc says, check everything you edited recently.

Categories

Resources