You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Emmanuel boudrant <eb...@noos.fr> on 2003/07/09 10:37:22 UTC
Jelly question
Hi,
Is it possible to update an xml file with Jelly ? For example, modify
the content of an attribute or a tag.
Thx,
-emmanuel
RE: Jelly question
Posted by Vincent Massol <vm...@pivolis.com>.
Jelly is extremely powerful (as is Java), but I personally prefer using
xmltask. Here's how you would modify an attribute:
<xmltask source="input.xml" dest="out.xml">
<attr path="web/servlet/context[@id='4']/" attr="id" value="test"/>
</xmltask>
looks simpler to me (provided you are ok adding a new jar to your build
classpath!).
-Vincent
> -----Original Message-----
> From: Paul Libbrecht [mailto:paul@activemath.org]
> Sent: 09 July 2003 13:42
> To: Maven Users List
> Subject: Re: Jelly question
>
> Well, with jelly, you can easily modify a stream of SAX events.
>
> But you can definitely parse a document, store it in a variable,
modify
> it (accessing it using XPath for example) then re-output it...
>
> Down here is such a snippet, it parses a bunch of files together and
> re-outputs it in one file...
>
> Do note that if you're using DTDs or Schemas, the default values
> specified there will come in...
>
> Also, do not that jelly has a strong tendency to ignore all whitespace
> by default (the trim attribute just about everywhere) which may or may
> not be wished...
>
> Paul
>
> <?xml version="1.0" encoding="utf-8" ?>
>
> <j:jelly
> xmlns:j ="jelly:core"
> xmlns:log ="jelly:log"
> xmlns:x ="jelly:xml"
> xmlns:ant ="jelly:ant"
> xmlns:util="jelly:util"
> xmlns:b="jelly:beanshell"
> >
>
> <log:info>Constructing File scanner.</log:info>
> <ant:fileScanner var="blopFiles">
> <ant:fileset dir="." includes="blop/**/dependency.xml"/>
> </ant:fileScanner>
>
> <log:info>File scanner constructed.</log:info>
> <!-- - amalgamate all files within one object -->
> <x:parse var="all_files">
> <my:allFiles xmlns:my="myNamespace">
> <j:forEach var="file"
items="${blopFiles.iterator()}">
> <j:set var="url"
value="${file.toURL()}"/>
> <log:info>Going around ${url}</log:info>
> <my:file
>
href="${url.toExternalForm()}">
> <j:include
uri="${url.toExternalForm()}"/>
> </my:file>
> </j:forEach>
> </my:allFiles>
> </x:parse>
>
>
> <!-- do something on there like something using
> x:forEach which goes around XPath elements -->
>
> <j:file name="someFile.xml" outputMode="HTML" ><!--
> prettyPrint="yes"
> -->
> <x:copyOf select="$all_files"/>
> </j:file>
>
> </j:jelly>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Jelly question
Posted by Paul Libbrecht <pa...@activemath.org>.
Well, with jelly, you can easily modify a stream of SAX events.
But you can definitely parse a document, store it in a variable, modify
it (accessing it using XPath for example) then re-output it...
Down here is such a snippet, it parses a bunch of files together and
re-outputs it in one file...
Do note that if you're using DTDs or Schemas, the default values
specified there will come in...
Also, do not that jelly has a strong tendency to ignore all whitespace
by default (the trim attribute just about everywhere) which may or may
not be wished...
Paul
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly
xmlns:j ="jelly:core"
xmlns:log ="jelly:log"
xmlns:x ="jelly:xml"
xmlns:ant ="jelly:ant"
xmlns:util="jelly:util"
xmlns:b="jelly:beanshell"
>
<log:info>Constructing File scanner.</log:info>
<ant:fileScanner var="blopFiles">
<ant:fileset dir="." includes="blop/**/dependency.xml"/>
</ant:fileScanner>
<log:info>File scanner constructed.</log:info>
<!-- - amalgamate all files within one object -->
<x:parse var="all_files">
<my:allFiles xmlns:my="myNamespace">
<j:forEach var="file" items="${blopFiles.iterator()}">
<j:set var="url" value="${file.toURL()}"/>
<log:info>Going around ${url}</log:info>
<my:file
href="${url.toExternalForm()}">
<j:include uri="${url.toExternalForm()}"/>
</my:file>
</j:forEach>
</my:allFiles>
</x:parse>
<!-- do something on there like something using
x:forEach which goes around XPath elements -->
<j:file name="someFile.xml" outputMode="HTML" ><!-- prettyPrint="yes"
-->
<x:copyOf select="$all_files"/>
</j:file>
</j:jelly>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
RE: Jelly question
Posted by Vincent Massol <vm...@pivolis.com>.
Not directly with Jelly, but you can use the excellent Ant xmltask from
http://www.oopsconsultancy.com/software/xmltask.html
-Vincent
> -----Original Message-----
> From: Emmanuel boudrant [mailto:eboudrant@noos.fr]
> Sent: 09 July 2003 10:37
> To: 'Maven Users List'
> Subject: Jelly question
>
> Hi,
>
> Is it possible to update an xml file with Jelly ? For example, modify
> the content of an attribute or a tag.
>
> Thx,
> -emmanuel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org