I can't figure out how to get proper XML Structure for resources in Android.
I've saved recepies.xml into values folder, and would like to pars them.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recepies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<recepie name="recepie1">
<item></item>
<NumberOfPersons>1</NumberOfPersons>
<Ingredients>
<string></string>
<string></string>
</Ingredients>
<Preparation></Preparation>
<Energy>342</Energy>
<Protein>8</Protein>
<RecipeCategory>3</RecipeCategory>
</recepie>
But, I get or "Invalid start tag",
if I format it without recipies tag like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?>
I get, no more pseudo attributes allowed.
If I use only this:
<?xml version="1.0" encoding="UTF-8"?>
I get that markup is not well formed.
I guess I'm missing something in basics of XML formatting, but I can't figure out what.
/res/values folder is only for android resources. You can only define one of these type of resources here.
http://developer.android.com/guide/topics/resources/available-resources.html
If you want your own xml file, place it in /assets folder.
Your resources in values.xml must look like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="string_name">text_string</string>
</resources>
You can check the documentation on string resources or on TypedArray to get more information.
Related
I have a question about values/strings.xml
I'd like to use strings.xml, but use another strings.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test">veeeeeeeeeeeeeeeeeeeeeeeery long script(about 1000characters)</string>
</resources>
like this, when I want to manage veeeeery long script by another xml file.
Then can I use another .xml file in values/strings.xml file?
for example like..
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
<string name="test"> #values/script.xml </string>
</resources>
Thank you for reading my question.
Have a nice day :)
Yes, you just need to use #string instead of #values
I created a new android studio project and found that there is no
<?xml version="1.0" encoding="utf-8"?>
tag at the beginning of strings.xml and styles.xml but it is present in colors.xml.
Why it is not present in the strings.xml and styles.xml?
Is the absence of this tag in strings.xml and styles.xml is fine?
Is that fine to add manually into strings.xml and styles.xml files?
Thanks!!!
<?xml version="1.0" encoding="utf-8"?> is called the "XML declaration" line and it is technically optional.
Why is it not present in the strings.xml and styles.xml?
That maybe due to a technical difficulty on your android studio which can be fixed with a restart.
Is the absence of this tag in strings.xml and styles.xml fine?
The presence of it is not compulsory but the absence of it may lead to compile time error when you insert non ASCII characters to the file, like Norwegian æ ø å , or French ê è é.
Is it fine to manually add it into strings.xml and styles.xml files?
Totally yes! And you even have extra options at your disposal
<?xml version="1.0" encoding="us-ascii"?>
<?xml version="1.0" encoding="windows-1252"?>
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-16"?>
I want to make new xml file in my value folder same as string.xml.
So in my app I make new xml file in value folder with name basic.xml and this xml contain string content like this:
basic.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World</string>
</resources>
But when I try to access this basic.xml in my main_activity.xml layout file in layout folder, then I can't be able to access basic.xml and its content.main_activity.xml
(Note - I am using eclipse.)
So how to make new string.xml like file in value folder properly and how to access it layout xml file. ?
Is there a way to add localization setting in my app? I'm going to add a preference/setting in my app and there is a localization option. So the user can change the language I have provided from the values string.
I was googling around but found nothing. Wondering you guys can help me, and give example or link to the tutorial.
You don't need to provide a setting for that, Android will do that for you. You just have to provide the translations for the languages you want to support.
You can do this for French for example by creating a folder named res/values-fr in your resources folder and putting your translations in there.
so in the res/values folder you would have a strings.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Map</string>
</resources>
and in the res/values-fr you woud have another string.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Carte</string>
</resources>
Your app will use the translation that best matches the language that the user has selected on their device.
I have a settings.xml file that I use to set various global variables within my app. I want to be able to create sub xml files that I include in the settings.xml file because depending on the client, I change settings in this file so I want to make it easier on myself.
I know that there is a way to include layout files this way but I can't find any documentation that shows how to do this with plain XML on Android.
Any help would be much appreciated.
I think all you have to do is make an additional file which includes the settings you want.
Ie, I have strings.xml in values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="main_title">Hello there</string>
</resources>
And I can create additionalstrings.xml in the values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="additional">How are you?</string>
</resources>
I can refer to either R.string.main_title or R.string.additional, without having to say the file it came from.