ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dominique Devienne" <ddevie...@gmail.com>
Subject Re: writing to XML
Date Thu, 01 May 2008 14:30:38 GMT
On Thu, May 1, 2008 at 9:15 AM, James Fuller
<james.fuller.2007@gmail.com> wrote:
> On Thu, May 1, 2008 at 4:01 PM, Guy Catz <Guy.catz@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


Mime
View raw message