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" />
Related
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
I have 2 xmls (they happen to be android text resources), the first one is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T1">AAAA</string>
</resources>
and the second is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T2">BBBB</string>
</resources>
I know the attribute of the element that I want to copy, in my example it's TXT_T1. Using python, how to copy it to the other xml and paste it right behind TXT_T2?
lxml is the king of xml parsing. I'm not sure if this is what you are looking for, but you could try something like this
from lxml import etree as et
# select a parser and make it remove whitespace
# to discard xml file formatting
parser = et.XMLParser(remove_blank_text=True)
# get the element tree of both of the files
src_tree = et.parse('src.xml', parser)
dest_tree = et.parse('dest.xml', parser)
# get the root element "resources" as
# we want to add it a new element
dest_root = dest_tree.getroot()
# from anywhere in the source document find the "string" tag
# that has a "name" attribute with the value of "TXT_T1"
src_tag = src_tree.find('//string[#name="TXT_T1"]')
# append the tag
dest_root.append(src_tag)
# overwrite the xml file
et.ElementTree(dest_root).write('dest.xml', pretty_print=True, encoding='utf-8', xml_declaration=True)
This assumes, that the first file is called src.xml and the second dest.xml. This also assumes that the element under which you need to copy the new element is the parent element. If not, you can use the find method to find the parent you need or if you don't know the parent, search for the tag with 'TXT_T2' and use tag.getparent() to get the parent.
This will work only for your simple example:
>>> from xml.dom.minidom import parseString, Document
>>> def merge_xml(dom1, dom2):
node_to_add = None
dom3 = Document()
for node_res in dom1.getElementsByTagName('resources'):
for node_str in node_res.getElementsByTagName('string'):
if 'TXT_T1' == node_str.attributes.values()[0].value:
node_to_add = node_str
break
for node_res in dom2.getElementsByTagName('resources'):
node_str3 = dom3.appendChild(node_res)
for node_str in node_res.getElementsByTagName('string'):
node_str3.appendChild(node_str)
if 'TXT_T2' in node_str.attributes.values()[0].value and node_to_add is not None:
node_str3.appendChild(node_to_add)
return dom3.toxml()
>>> dom2 = parseString('''<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T2">BBBB</string>
</resources>''')
>>> dom1 = parseString('''<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T1">AAAA</string>
</resources>''')
>>> print merge_xml(dom1, dom2)
<?xml version="1.0" ?><resources>
<string name="TXT_T2">BBBB</string><string name="TXT_T1">AAAA</string></resources>
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
Here's one that's driving me crazy:
I have recently started looking into Appcelerator Titanium. I have built a few small apps both with a normal project and using Alloy so I understand the basics at least.
One thing I just cannot get working is the i18n folder/files.
Here is what ive done:
- Create a "Default Project"
- add folder to root directory "i18n"
- add "en" and "es" folder to "i18n"
- add "strings.xml" to both those new folders.
- added:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome TEST</string>
</resources>
to both the strings.xml, except in the es strings I put "ES Welcome TEST".
- In Resources -> app.js I changed "I am Window 1" to L('welcome_message')
- Ran the application
Both the normal and alloy versions just show a blank screen. I would like to get my alloy app working the most but from what I understand the localization code should work the same in both apps. In alloy I may just have to put it in the style.
Any pointers would be great! I have looked at other post claiming its not working but all of them were either syntax errors or just set it up wrong. I have copied their code and have the exact same issue with it not working so I have a feeling im missing a newbie step.
-- Here are some screenshots, I just created a brand new regular(not alloy) project, added the code above and try to use L('welcome_message') to no luck. I tried installing everything on a new PC to make sure I wasn't messing anything up on my main computer.
Heres the answer:
https://wiki.appcelerator.org/display/guides/Internationalization
Ends up by default your manifest file is not setup by default to allow localization UNLESS you choose a tabbed project.
Kinda silly if you ask me.
For the topic poster:
My new string.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Don't Help Austin</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
Screenshot of my non-Alloy experiment:
For those looking to answer the question in the topic, this is a possible answer below.
My i18n folder is on the same hierarchy level as app and plugins, so mine isn't inside the app folder like the rest of the Alloy resources.
index.xml
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick"></Label>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: L("welcome_message")
}
strings.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
When I placed the L("welcome_message") inside the index.xml, it didn't work.
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>