LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-09-2012, 10:32 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Rep: Reputation: 81
android - how to access strings in a custom xml file in res/values?


I have this file in res/values. Say it's X.xml where I have some strings inside:

Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    
    <!-- 
    	wether we are on a release or not
    	Values: true or false
    -->
    <string name="release">false</string>
    <string name="base_uri">http://blahblah</string>
    
    <!--  for testing purposes -->
    <string name="default_username">username</string>
    <string name="default_password">password</string>
    
</resources>
How can I access those values in code? Thanks in advance.
 
Old 11-09-2012, 01:37 PM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 3 / CrunchBang Linux 10 Statler / Easy Peasy
Posts: 4,293

Rep: Reputation: 205Reputation: 205Reputation: 205
You might get a quicker response if you post your question here: Android Questions. No need to register, log in using your LQ credentials.
 
Old 11-10-2012, 01:02 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
What do you even mean by "access", in terms of a smartphone? How do you expect to be able to extract the values, and what would you do with them? When you say "code", do you mean some programming language? Are you trying to create an app or something?


If this were a regular Linux system, with access to a shell and arbitrary programs, and you just needed some way to extract the text values, then I'd suggest something like xmlstarlet:

Code:
$ xmlstarlet sel -T -t -v '//string[@name="base_uri"]' -n file.xml
http://blahblah
But I have no idea what's possible on android. I agree that you should go to the androidquestions forums for this. And be sure to define your needs clearly.
 
Old 11-10-2012, 01:13 PM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Original Poster
Rep: Reputation: 81
I don't understand why you sound so ill-tempered. It's "native" android so we're talking about plain old java here.

In android there's a res/values/strings.xml file and you get the values contained inside with something as simple as (from inside one activity, for example):

Code:
getResources().getString(R.string.myValue);
R's members are kept in sync with the <string /> values you add to strings.xml automagically so it's very straight forward. Now I'd like to separate some of the values to another file and would like to be able to access the values contained there in (with the same ease would be very convenient).
 
Old 11-10-2012, 01:35 PM   #5
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,550

Rep: Reputation: 513Reputation: 513Reputation: 513Reputation: 513Reputation: 513Reputation: 513
as a hax you can load something like connectbot or sshdroid and log into your fone and use regular commands like grep/sed/awk to parse the data you want.
 
Old 11-13-2012, 10:11 AM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,956
Blog Entries: 1

Original Poster
Rep: Reputation: 81
Having the file not in res/values but in res/xml I was able to pull it off following this article: http://www.41post.com/4015/programmi...rom-a-xml-file

Cheers!
 
  


Reply

Tags
android, custom file, resources, strings, values


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extarct tags with multiline values from XML file using sed/Awk gbms Linux - Newbie 3 03-27-2012 10:18 AM
[SOLVED] parsing custom xml file in java segmentation_fault Programming 5 01-04-2012 12:51 PM
Working with strings in an xml file C++ vbx_wx Programming 1 03-08-2011 05:42 AM
Sorting specific values from an XML file canimsin Programming 5 09-21-2010 10:48 PM
need to get data from xml file to MySQL database, and then use php to access Armon Linux - General 1 01-18-2006 02:54 PM


All times are GMT -5. The time now is 08:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration