You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Guy Catz <Gu...@waves.com> on 2008/05/01 08:56:29 UTC
RE: writing to XML
Hi.
What I actually need, is to write data into a XML file, so I will be
able to render this XML to a HTML as a report.
The XML structure is something I know.
Thanks.
-----Original Message-----
From: Brian Agnew [mailto:brian@oopsconsultancy.com]
Sent: Wednesday, April 30, 2008 8:10 PM
To: Ant Users List
Cc: user@ant.apache.org
Subject: Re: writing to XML
Where are you getting the XML node from ?
XMLTask ( http://www.oopsconsultancy.com/software/xmltask/ ) may do what
you require.
Brian
On Wed, April 30, 2008 17:10, Guy Catz wrote:
> hi guys,
>
> I'm trying to write a node to XML file.
> Is it possible to do that from ANT?
>
> something like the XMLProperty which read from XML, just the
opposite..
> :)
>
> Thanks.
> Guy.
>
--
Brian Agnew http://www.oopsconsultancy.com
OOPS Consultancy Ltd
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by Gilbert Rebhan <an...@schillbaer.de>.
James Fuller schrieb:
> On Thu, May 1, 2008 at 4:01 PM, Guy Catz <Gu...@waves.com> wrote:
>> Thanks guys, that's very helpful.
>>
>> But, once I've used echoxml to write into a file, can I use it again to
>> add more values, in append mode?
> <someelement/>
> <someelement/>
> <someelement/>
> <someelement/>
> <someelement/>
> <someelement/>
>
> the above would not be valid xml
with <echo> something like =
<echo file="foobar.xml" append="true">
<![CDATA[
<someelement/>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
]]>
</echo>
would be possible, if it's valid xml or not,
whereas <echoxml> task accepts only valid xml.
Just make sure that the first <echo> in the workflow
has an opening <somerootelement> and the last <echo> in
the workflow has a closing </somerootelement> to get a
valid xml file after all.
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by Brian Agnew <br...@oopsconsultancy.com>.
I don't want to sound like a broken record (!) but at the risk of sounding
like one, this is precisely what XMLTask will do (including inserting XML
with non-root nodes into existing documents, appending XML elements and
fragments incrementally etc.).
Anyway - that's my lot for the moment :-)
Brian
On Thu, May 1, 2008 15:30, Dominique Devienne wrote:
> On Thu, May 1, 2008 at 9:15 AM, James Fuller
> <ja...@gmail.com> wrote:
>> On Thu, May 1, 2008 at 4:01 PM, Guy Catz <Gu...@waves.com> wrote:
>> > Thanks guys, that's very helpful.
>> >
>> > But, once I've used echoxml to write into a file, can I use it again
>> to
>> > add more values, in append mode?
>>
>> yes but an xml file with no root parent is invalid xml ;)
>>
>> e.g. if u just append an xml element
>> elements...
>> the above would not be valid xml
>> <somerootelement> elements... </somerootelement>
>> is valid xml
>
> You can work around this by using two files, a "fixed" one with the
> root element and defining a system entity referring to the second
> "dynamic" file containing children of the root, where the root element
> simply refers to the external entity:
>
> ----------- root.xml ----------
> <?xml ... /?>
> <!DOCTYPE root [
> <!ENTITY children SYSTEM "children.xml">
> ]>
> <root>&children;</root>
>
> ------ children.xml -------
> <child />
> <child />
> ...
>
> Write root.xml once, then append to children.xml. If you write a full
> child each time, your document remains valid. --DD
>
> PS: Since last-modified date of root.xml doesn't change when appending
> to children.xml, you may want to <touch/> root.xml when appending too.
>
> PPS: Caveat: Non-validating parsers are not required to resolve
> entities declared outside the document (in the external subset). In
> fact, non-validating parsers may not perform entity expansion at all.
> But this worked for me in the past.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
--
Brian Agnew http://www.oopsconsultancy.com
OOPS Consultancy Ltd
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by Dominique Devienne <dd...@gmail.com>.
On Thu, May 1, 2008 at 9:15 AM, James Fuller
<ja...@gmail.com> wrote:
> On Thu, May 1, 2008 at 4:01 PM, Guy Catz <Gu...@waves.com> wrote:
> > Thanks guys, that's very helpful.
> >
> > But, once I've used echoxml to write into a file, can I use it again to
> > add more values, in append mode?
>
> yes but an xml file with no root parent is invalid xml ;)
>
> e.g. if u just append an xml element
> elements...
> the above would not be valid xml
> <somerootelement> elements... </somerootelement>
> is valid xml
You can work around this by using two files, a "fixed" one with the
root element and defining a system entity referring to the second
"dynamic" file containing children of the root, where the root element
simply refers to the external entity:
----------- root.xml ----------
<?xml ... /?>
<!DOCTYPE root [
<!ENTITY children SYSTEM "children.xml">
]>
<root>&children;</root>
------ children.xml -------
<child />
<child />
...
Write root.xml once, then append to children.xml. If you write a full
child each time, your document remains valid. --DD
PS: Since last-modified date of root.xml doesn't change when appending
to children.xml, you may want to <touch/> root.xml when appending too.
PPS: Caveat: Non-validating parsers are not required to resolve
entities declared outside the document (in the external subset). In
fact, non-validating parsers may not perform entity expansion at all.
But this worked for me in the past.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by James Fuller <ja...@gmail.com>.
On Thu, May 1, 2008 at 4:01 PM, Guy Catz <Gu...@waves.com> wrote:
> Thanks guys, that's very helpful.
>
> But, once I've used echoxml to write into a file, can I use it again to
> add more values, in append mode?
yes but an xml file with no root parent is invalid xml ;)
e.g. if u just append an xml element
<someelement/>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
the above would not be valid xml
<somerootelement>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
<someelement/>
</somerootelement>
is valid xml
> I need to add values to my XML file in different tasks, not in one
> place.
perhaps you just want to define a template xml with tokens that you replace ?
hth, Jim Fuller
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: writing to XML
Posted by Guy Catz <Gu...@waves.com>.
Thanks guys, that's very helpful.
But, once I've used echoxml to write into a file, can I use it again to
add more values, in append mode?
I need to add values to my XML file in different tasks, not in one
place.
Please advice,
Thank you very much,
Guy.
-----Original Message-----
From: Steve Loughran [mailto:stevel@apache.org]
Sent: Thursday, May 01, 2008 12:22 PM
To: Ant Users List
Subject: Re: writing to XML
Guy Catz wrote:
> Hi.
>
> What I actually need, is to write data into a XML file, so I will be
> able to render this XML to a HTML as a report.
> The XML structure is something I know.
>
> Thanks.
>
There is an <echoxml> task that takes well formed XML and echoes it.
<echoxml file="subbuild.xml">
<project default="foo">
<target name="foo">
<echo>foo</echo>
</target>
</project>
</echoxml>
One thing you have to watch out for here is namespace games. If you want
xml in a new namespace
-declare the namespaces inside the echoxml
-keep it all explicit
-check the output by hand to see that it looks ok
you can use <xmlvalidate> and <schemavalidate> to automate those checks
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by Steve Loughran <st...@apache.org>.
Guy Catz wrote:
> Hi.
>
> What I actually need, is to write data into a XML file, so I will be
> able to render this XML to a HTML as a report.
> The XML structure is something I know.
>
> Thanks.
>
There is an <echoxml> task that takes well formed XML and echoes it.
<echoxml file="subbuild.xml">
<project default="foo">
<target name="foo">
<echo>foo</echo>
</target>
</project>
</echoxml>
One thing you have to watch out for here is namespace games. If you want
xml in a new namespace
-declare the namespaces inside the echoxml
-keep it all explicit
-check the output by hand to see that it looks ok
you can use <xmlvalidate> and <schemavalidate> to automate those checks
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: writing to XML
Posted by Gilbert Rebhan <an...@schillbaer.de>.
Guy Catz wrote:
> Hi.
>
> What I actually need, is to write data into a XML file, so I will be
> able to render this XML to a HTML as a report.
> The XML structure is something I know.
>
ant > 1.7.0 =
<echoxml file="foobar.xml">
your xml goes here
</echoxml>
ant < 1.7.0 =
<echo file="foobar.xml">
<![CDATA[
your xml goes here
]]>
</echo>
maybe you need to use =
<echoxml file="..." append="true">
or
<echo file="..." append="true">
if you want to write to an existing file
and append your data to that file
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org