ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Levy-Lambert <anto...@antbuild.com>
Subject AW: Custom ant task with nested 'literal' XML data fragment?
Date Fri, 24 Oct 2003 05:52:25 GMT
Hi Patrick,
it is perfectly possible to write a custom task which will accept the nested
literal XML data fragment.
You might want to take a look at the <echo/> task and at the <replace/>
task.

in your build file, you need to enclose your XML fragment in <![CDATA[
section like this :
<xslt in="foo.xml" out="bar.xml>
  <style><![CDATA[
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
      <xsl:template match="something">
	<!-- more random xslt stuff -->
      </xsl:template>
    </xsl:transform>
    ]]>
  </style>
</xslt>

Your build file fragment suggests that you have an <xslt> task with a
<style> nested element.
In the class representing in Java the style nested element you need then to
insert this method :
(copied from org.apache.tools.ant.taskdefs.Echo) :
    /**
     * Set the XSL fragment inline.
     */
    public void addText(String msg) {
        // replaceProperties allows as its name suggest to replace
${something} tokens with their value.
        xsltext = getProject().replaceProperties(msg);
    }

Hopes this helps,

Antoine

-----Ursprungliche Nachricht-----
Von: Patrick Surry [mailto:Patrick.Surry@quadstone.com]
Gesendet: Freitag, 24. Oktober 2003 02:55
An: Ant Users List
Betreff: Custom ant task with nested 'literal' XML data fragment?


I'm not sure if this question should be on this list or the developer one,
but
what the heck:

Wondering if it's possible to create a custom ant task that takes a
'literal'
XML fragment as a nested element, which it can process directly as XML data,
rather than trying to specify setXXX methods for every potential element
within
the nested XML data.

For example, say I wanted to extend the XSLT task so that it could take a
stylesheet 'inline' as a nested element:

<xslt in="foo.xml" out="bar.xml>
  <style>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
      <xsl:template match="something">
	<!-- more random xslt stuff -->
      </xsl:template>
    </xsl:transform>
  </style>
</xslt>

Obviously the task would just want to process the whole XML fragment within
'<style>' as a blob of XML rather than defining setXSL:Transform(),
setXSL:Template(), ... etc (not that those are even valid syntax).

My application is similar in that I want to optionally allow some XML data
'inline' in the buildfile rather than having it live in a separate file.  I
guess I could put the XML in <![CDATA[ ... ]]> and have the task deal with
it
as text which it then parses separately, but that seems a bit ugly.

Might also be cool if it could pre-process ${...} property substitutions in
the
literal XML but I'd need to think about whether that makes sense or not.

Any ideas?  Sorry if this is the wrong list or not in Ant's intended
spirit...

Thanks,
Patrick




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message