Hello!
I've got a question coupled a problem here, and I'm really hoping
someone can help me out.
I'm working on a reader & writer using Xerces for a GIS format (I don't
think it matters which). I've been only interested in parts of the the
format during read so I'm currently throwing away sub-trees that don't
interesting me. I'd like to change that though, and preserve those
'uninteresting' pieces so that my writer can put them back in when it's
time to write out the result.
To that end I was planning on building DOMDocumentFragments for
sub-trees that I don't care about. It seems particularly well-suite for
this task and I quite like the class. But then I started thinking about
XMLPlatformUtils::Intialize()/Terminate() -- I think my Document
Fragments may get cleaned up before I can use them!
I've got the reader & writer as separate objects -- that's a requirement
of the my task. They need to be self-contained, opaque objects so I've
put the Intialize()/Terminate() calls in the constructor & destructor
respectively for the two objects. Now, if I store my document fragments
in my interim objects, do something to them, and then pass that to the
writer to serialize, I'm afraid these fragments will be freed if the
reader is destroyed before the writer is finished. For example:
---- snip ----
MyReader reader("somefile.xml");
MyData data = reader.Read();
MyWriter writer("output.xml");
writer.Write(data);
--------------
Should work fine, I think. On the other hand:
---- snip ----
MyReader* reader( = new MyReader("somefile.xml");
MyData data = reader.Read();
delete reader;
MyWriter writer("output.xml");
writer.Write(data);
--------------
I think this would cause any DOMDocumentFragment pointers I stick in the
MyData collection to be released. Is that right?
If not I'm good to go. Otherwise though, I need a way to store these
fragments until it's time to write them out. At present, the only way I
can think of would be to serialize the fragments to a string using
DOMWriter, and then in MyWrite::Write() to use a DOMBuilder to parse
these fragment strings back into DOMDocumentFragments, plug them into
place and let the writer do it's thing. That's pretty ugly though.
Assuming this is an issue, has anyone got a suggestion for how I can do
this? Any help would be greatly appreciated!
..............................
Andrew Patterson
Software Engineer
Avenza Systems Inc.
email: andrew@xxxxxxxxxx
phone: 416.487.5116
|