I am trying to transform the android xml into Plist but i am facing the issue because the Android XML contains COLONS in the attribute names as follows:
<PreferenceCategory android_title="Identity" >
<EditTextPreference
android:key="systemname"
android_title="System Name" />
</PreferenceCategory>
So when i try to read the attribute value using XSLT it gives the following error:
XPath evaluation returned no result.
I am bit new to XSLT, So can any one help me reading the attribute value which have colon in their names as mentioned above.
Please read about XML Namespaces, a good starting point can be XML Namespaces tutorial on w3schools.com to know about the usage of "colons".
You could read the MSDN article about XML Namespaces and How They Affect XPath and XSLT to know more.
I managed by using the exclude-result-prefixes attribute inside in XSLT.
My stylesheet tag looked like below.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:android="http://schemas.android.com/apk/res/android"
exclude-result-prefixes="android">
exclude-result-prefixes attribute is used if you want to exclude any namespace during compile time.
Related
What I am want to do is the same as this question.
The question could be divided into two-part.
First, Referencing to string in a custom XML file, thanks to the author of the question I mentioned above, this is solved.
Second, and is what I am asked, How to show an autocomplete popup dialog to select string when typing string like #string.
The question I mentioned has been asked about four years ago and I think the second part of the question is also need to solve, without autocomplete, typing string is so unbearable.
I try to do like XSD - Autocomplete and Validate XML in IDE, but I failed.
I have made it.
Roughly speaking, Create a schema of the XML and apply it. With a schema, the IDE could know your XML file structure and then give the popup dialog to show available options.
If you are newer at schema, don't afraid, because it is easy to understand and we could use Android Studio to generate it.
How to generate a schema file?
First, select your XML file, then key ctrl + shift + A to show the actions input dialog. Key in "Generate" you will find the action of Generate XSD file from XML file ..., magically a schema for your XML will be created for you.
And then apply it to your XML, and how?
I think I don't have to show the concrete steps since it's unnecessary. (Probably it may be nobody to see it and I write here mainly leave a note for me)
I encounter the biggest problem is how to define the restriction for the attribute. how I make it?
In my Gradle task, I use the java parser parser the file of R.java and get a list of String then create .xsd file to create a restriction type. Then, in the main '.xsd' file, include it, and apply the type to the attribute.
// file: cartype.xml our target
<Car>
<item boxId="1" bandName="#string/xxx" ... />
</Car>
// define a type for the attriute of bandName and tell what can be select
<xs:simpleType name="AndroidStringType">
<xs:restriction >
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="itemType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="boxId"/>
// apply the type to the attribute
<xs:attribute type="AndroidStringType" name="bandName"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
This question already has answers here:
Error: The processing instruction target matching "[xX][mM][lL]" is not allowed
(10 answers)
Closed 3 years ago.
I'm trying to implement facebook login in my app so I followed facebook instructions and I needed to create strings.xml file because I didn't have this file, but when I start the app I get this error:
Execution failed for task ':app:mergeDebugResources'.
Error: The processing instruction target matching "[xX][mM][lL]" is
not allowed.
My strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">name</string>
<string name="facebook_app_id">00000000000</string>
<string name="fb_login_protocol_scheme">fb000000000000</string>
</resources>
What should I do to solve this problem?
Leave out the <?xml ...> XML declaration alltogether. This error is reported when an XML declaration (which is syntactically an SGML processing instruction) is found in XML other than at the beginning of the XML. So I'm guessing the XML is composed/appended to some other XML in your app (it's impossible to say without additional info). An XML declaration is optional anyway; it's only used to tell a parser the encoding of the document, and that markup should be parsed according to XML rules (rather than HTML or generic SGML rules). You also might want to double-check you put no invisible garbage characters (by string operations in your app code) into your XML.
I am using a Java class to import data to my app from a .csv file. I found some examples online, and this is what they seem to do. However, it's showing the error: Error parsing XML: unbound prefix. The research I've done on this indicates that it is usually a spelling error. If it is, I can't find it. Here is the section where I am having the problem.
<provider android:name="com.ATS_Boxes.ContentProvider.class"
android:authorities="ContentProvider"></provider>
You appear to be trying to declare a provider in an Android resource file - that isn't possible. You can only declare providers in your project's manifest file (AndroidManifest.xml, in the root directory of your project).
Also, although I'm not sure if it makes any difference, the first line in the xml code you provided as comment reads:
<!--?xml version="1.0" encoding="utf-8"?-->
That looks like it's commented out. Normally it should look like:
<?xml version="1.0" encoding="utf-8"?>
post the entire XML file.
My guess is that you do not have the 'android' namespace declared so its puking when it's parsing the attributes android:name and android:authorities
I have an XML file:
<building>
<room IMAGE="R.raw.room" />
</building>
but I don't know how to link the value of IMAGE to my main program... When I do this:
[... parsing xml file and detect room ...]
ImageView image = findViewByID(xml.getAttributeValue(0));
it don't works.. Cause it returns me a String and not a int. How can I link this XML file to my resources?
Please help!
Have you tried using getResources().getIdentifier()?
Answered here
R.raw.room is an identifier generated by compiler for a file. You cannot load from XML. What do you want to achieve?
I would like to know whether there is a way to insert/inject a <string> element defined in an XML file into another <string> element, doing that just with XML.
For example I could have:
<string name="author">Francesco</string>`
and I am looking for something like:
<string name="about_application">Author: #string/author</string>`
so that getString(R.string.about_application) would result in "Author: Francesco".
I know that I could combine the two elements in Java code using String.format(string, formatArgs)like for example:
<string name="author">Francesco</string>
<string name="about_application">Author: %1$s</string>`
and then in code use
String.format(getString(R.string.about_application), getString(R.string.author))
but I would like to do it in XML directly.
Can anyone suggest me a way to do it?
If I understand what you are looking to do, then internal (parsed) general entities might help you achieve what you are looking for.
An example of how you can define the value "Francesco" as an entity called "auth" and then use it in your XML:
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ENTITY auth "Francesco">
]>
<doc>
<string name="author">&auth;</string>
<string name="about_application">Author: &auth;</string>
</doc>
When read by an XML parser, the document will be parsed and evaluated, or "seen", as:
<?xml version="1.0"?>
<doc>
<string name="author">Francesco</string>
<string name="about_application">Author: Francesco</string>
</doc>
Unfortunately I don't think that is possible. I asked a similar question a while ago, and was told it wasn't possible.
Gradle plugin 0.10 brings what they call manifestPlaceholders which basically does what you need but this feature currently only work in the AndroidManifest. There is although an issue opened targeting the next Android build version 1.4 (1.3 is currently in beta4 so should be near RC1 and could see a 1.4 beta1 soon hopefully).
This issue should expand the placeholders in xml configurations files (I just pray this will include strings file and not only basic xml configuration).
From: http://tools.android.com/tech-docs/new-build-system
For custom placeholders replacements, use the following DSL to
configure the placeholders values :
android {
defaultConfig {
manifestPlaceholders = [ activityLabel:"defaultName"]
}
productFlavors {
free {
}
pro {
manifestPlaceholders = [ activityLabel:"proName" ]
}
}
will substitute the placeholder in the following declaration :
<activity android:name=".MainActivity"> android:label="${activityLabel}" >
Can't wait to try it out. This way you could put a placeholder in multiple occurence in the strings file and define the value only in one place instead of modifying all java files to add an argument with %1$s
For now the only clean solution is although the entity trick but this will not work if you want to override the value in flavors since the entity must be defined in the same xml file.
Yes it is possible, I've created this small library that allows you to resolve these placeholders at buildtime, so you won't have to add any Java/Kotlin code to make it work.
Based on your example, you'd have to set up your string like this:
<string name="author">Francesco</string>
<string name="about_application">Author: ${author}</string>
And then the plugin will take care of creating the following:
<!-- Auto generated during compilation -->
<string name="about_application">Author: Francesco</string>
More info here: https://github.com/LikeTheSalad/android-stem