Re: [xml] How to retrieve filename from xmlTextWriter
- From: Daniel Veillard <veillard redhat com>
- To: Zoltán Ördögh (GMail) <csimbi gmail com>
- Cc: xml gnome org
- Subject: Re: [xml] How to retrieve filename from xmlTextWriter
- Date: Fri, 15 Mar 2013 10:22:41 +0800
On Thu, Mar 14, 2013 at 07:12:34PM -0400, Zoltán Ördögh (GMail) wrote:
Hi all,
I am exporting data from binary format to XML.
Most of the data fits nicely into the XML document, it looks nice, tidy and
easy to read.
However, there are a few large blocks of data. For example, 4k floats is
not very useful as a BASE64 encoded string, and having 4k elements is not
very useful, neither.
So, I thought I'd export these blocks 'as-is', into binary format, as a
separate file, right next to the XML file and store the location on the
binary file into the XML instead.
To achieve this, I'd need to find out the URI of the XML file being written
(so I can change the file extension from XML to BIN and write the file to
the same place where the XML is).
Unfortunately, the xmlTextWriter does not have any members that would give
me the URI.
Is there any legitimate way to figure it out - one that I must have missed?
The thing is, I would not want to update all classes involved just to pass
down the URI of the XML document; it would be far better go get the
filename on the spot, using the xmlTextWriterPtr that's already passed down.
But you can use a writer to a file descriptor, or any method of I/O
you want to build.
xmlNewTextWriterFilename()
calls
__xmlOutputBufferCreateFilename(const char *URI,...
and there we use the I/O layer to create a context used by the
I/O layer to push data, but that context is completely opaque
and at the xmlOutputBuffer level we don't keep informations like
the URI
http://xmlsoft.org/html/libxml-tree.html#xmlOutputBuffer
-------------------------------
struct _xmlOutputBuffer {
void* context;
xmlOutputWriteCallback writecallback;
xmlOutputCloseCallback closecallback;
xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
xmlBufPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */
xmlBufPtr conv; /* if encoder != NULL buffer for output */
int written; /* total number of byte written */
int error;
};
-------------------------------
So as-is, I'm sorry that's not possible, you will have somehow
to keep the data around, as libxml2 doesn't store it there.
Another way would be to design and register your own I/O layer for
file access and store that filename as part of the returned context
used by your own I/O routines.
Daniel
--
Daniel Veillard | Open Source and Standards, Red Hat
veillard redhat com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | virtualization library http://libvirt.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]