Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Appending to XML file and keeping XML well-formed

24 views
Skip to first unread message

blu4899

unread,
May 21, 2002, 1:18:45 AM5/21/02
to
Hi,

I am using java to append to an XML-based log file. The basic
structure is

<root>
<log_entry .../>
<log_entry .../>
...
</root>

The problem is to add new log_entry records at the end and keep the
closing tag </root>. The log files can get very big, so I don't want
to read the file every time into memory, let alone run an XML parser
over it. I need the XML to be well-formed in between log writes, so I
can run XSL transformations over it.

Did anybody here come across the same problem? What's the most elegant
and efficient way solving it? Random-access file operations, XML
include techniques?

Thanks for any help,
blu

Bill Michaelson

unread,
May 21, 2002, 1:25:59 AM5/21/02
to
Why not leave the </root> off, and only append it on-the-fly whenever
you need to run the XSL transformation?

Philippe Poulard

unread,
May 21, 2002, 7:54:18 AM5/21/02
to

I heard about a tool that may help you :
http://jakarta.apache.org/log4j/docs/index.html
I don't know if it is an XML based tool
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------

Marrow

unread,
May 21, 2002, 9:01:23 AM5/21/02
to
Hi blu,

You could use a SYSTEM entity to include a non-well formed XML document into
another.

For example...

== LogStub.xml ==========================
<?xml version="1.0"?>
<!-- doc type for static include of external data -->
<!DOCTYPE staticinc [
<!ENTITY logentries SYSTEM "LogEntries.xml">
]>
<root>
<!-- include the non-well formed XML -->
&logentries;
</root>
== end of LogStub.xml =====================

and...

== LogEntries.xml ========================
<log_entry datetime="2002-05-21T09:00"/>
<log_entry datetime="2002-05-21T10:00"/>
<log_entry datetime="2002-05-21T11:00"/>
<log_entry datetime="2002-05-21T12:00"/>
== end of LogEntries.xml ===================

If you then run the transformation against LogStub.xml the nodes from
LogEntries.xml will be available as though they were actually in the LogStub.xml
document.

Be careful not to have an XML declaration (i.e. <?xml version="1.0"?>) in the
LogEntries.xml - as this would cause the whole XML to be non well-formed. Also,
when you load the LogStub.xml into a DOM make sure that the DOM does not try to
validate the XML - or it will fail because the XML isn't valid according to the
partially defined DTD (i.e. set .validateOnParse to false).

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


blu4899 wrote in message <42939489.02052...@posting.google.com>...

Richard Tobin

unread,
May 24, 2002, 2:03:30 PM5/24/02
to
In article <f2oG8.1004$Pw.2...@news8-gui.server.ntli.net>,
Marrow <marrow-NO-@-SPAM-marrowsoft.com> wrote:

><root>
> <!-- include the non-well formed XML -->
> &logentries;
></root>

>== LogEntries.xml ========================


><log_entry datetime="2002-05-21T09:00"/>

...

>Be careful not to have an XML declaration (i.e. <?xml version="1.0"?>) in the
>LogEntries.xml - as this would cause the whole XML to be non well-formed.

You can have an XML declaration in the entity provided it has an
encoding declaration (it's technically a "text declaration" in this
case). The text declaration in an external parsed entity is not
considered part of its replacement text - see

http://www.w3.org/TR/REC-xml#sec-TextDecl

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!

0 new messages