I have no problem making JAXP read in XML and tinker with it (I'm using DOM). But I want to have it spit XML into a string for me. How do I go about that?
I don't think the JAXP package has a convenient way to do that, but the Xerces parser is supposed to have a: org.apache.xml.serialize.XMLSerializer that will do it. I have not tried it yet. That would seem to be an obvious thing to have in a XML toolkit, dunno why they left it out.
I guess that the reason they left it out is to avoid bloating the system for the few people who do need it. A basic DOM->XML processor is not hard to write, but it's easy to get bogged down in style issues (generate '<ugh/>' or '<ugh></ugh>'? use '<' or '<![CDATA[' ? and so on. I regard this is a fine example XML application, but not part of an XML parser. My own XML parser uses subclassing for this. One class for the actual parser, with a child class which adds XML output. I've never used the XML output facility apart from internal tests, and for several applications I just don't include that class in the archive. Most of my XML text is generated either by hand, using an XML tree editor or just a regular text editor, or using XSLT or some templating mechanism. Do you have an actual application in mind, or is this just a theoretical need?
I have a real need. I have an object that I want to make persistant. This object contains objects which contain objects. Our persistance layer is Oracle. I'm thinking that I'll store the sub objects as an XML string rather than making a bunch of tables.
I've just seen this on the Resin mailing list, and haven't tried it yet... > From: Brad Clow <brad@workingmouse.com> > > we use: > document.getFirstChild().toString() Anyone want to try it with JAXP or another DOM implementation?