Out of all these, I'd recommend #7, an xslt task, as this is the tool
most directly suited to manipulate XML. While you could use any of the
others (except I'd discourage #1 for any production purpose!), it gets
more and more complex if you make more changes.

Here's a simplification of the XSLT script I use for this task (my
script does several other things as well).  If you work with XML at
all, it's well worth learning to use XSLT.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:android='http://schemas.android.com/apk/res/android'
    >
    <xsl:param name="VERSION"/>

    <xsl:output indent="no"/>

    <!-- Supplies a newline after the XML header. It's cosmetic, but
something to include in each script. -->
    <xsl:template match="/">
        <xsl:text>
</xsl:text>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>

    <!-- This is the part that makes the desired change.
         One template like this for each change you want to make. -->
    <xsl:template match="/manifest/@android:versionName">
        <xsl:attribute name="android:versionName"><xsl:value-of
select="$VERSION"/></xsl:attribute>
    </xsl:template>

    <!-- Identity transform by default. Generally, you'll put this in
each script you write,
         if you're just making changes. It copies everything unchanged
that doesn't have its own
         template. -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

--
And I invoke it like this (again, simplified):
            <xslt in='${loc.project}/AndroidManifest.xml'
                  out='${loc.project.bui...@{type}}/AndroidManifest.xml'
                  style='configureManifest.xsl'
                  force='true'>
               <param name='VERSION' expression="${BUILD}"/>
            </xslt>

The @{type} there is because I put this into a macrodef, to make it
easy to reuse to make different types of builds, doing things like
including/omitting various activities, and other build-time
customization.


On Dec 28, 12:38 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> Option #1: Edit it by hand
>
> Option #2: Write a Java/Ruby/sed/whatever program to modify the data
> and call that from an Ant Exec task
>
> Option #3: Write a custom Ant task
>
> Option #4: Use the Replace or ReplaceRegExp tasks
>
> Option #5: Use a Script task and a Beanshell/Groovy/whatever script
>
> Option #6: Use a Translate task
>
> Option #7: Use an XSLT task
>
> This, of course, would be a better question to ask someplace that is
> relevant, such as an Ant discussion list. The fact that you happen to
> be modifying an XML file from Android is not nearly as important as
> the tool you seem to wish to use to modify it (Ant).
>
> BTW, the Ant manual is at:http://ant.apache.org/manual/index.html
>
>
>
>
>
>
>
>
>
> On Tue, Dec 28, 2010 at 3:20 PM, sashad <olexanderdanc...@gmail.com> wrote:
> > HI Guys,
>
> > I would like to override  android:versionName attribute that is
> > located in AndroidManifest.xml
> > here is a sample
> > <?xml version="1.0" encoding="utf-8"?>
> > <manifest android:versionCode="1"
> >        android:versionName="1.0" />
>
> > I found ant code to read this value using xPath
>
> > <xpath input="AndroidManifest.xml"
> >           expression="/manifest/@android:versionName"
> >           output="${manifest.versionName}"/>
>
> > but I cannot find how to write this value using build ant script
> > I am looking for some easy to implement way
>
> > Please suggest,
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 2.2 Programming Books:http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to