Dave, it's only good that you find the code snippet useful, sometimes i wonder why such elementary things are not available in FAQs or HOW-TO docs, because in this case i believe that many wants to serialize a DOM tree back to an XML string after manipulation. Yes, that code does the job just fine.
Yes, i just found out today that when i do an oformat.setDoctype(null, "cheers"); it does not set the doctype to "cheers", the original is used instead. I have no idea about this effect, i bet it is a bug because usually one believes that a Set() function works properly. cheers, Peter > -----Urspr�ngliche Nachricht----- > Von: Dave Barfield [mailto:[EMAIL PROTECTED] > Gesendet: Freitag, 5. April 2002 12:04 > An: [EMAIL PROTECTED] > Betreff: Re: AW: Setting a DOCTYPE Declaration through > DocumentType for > a bran d ne w document > > > > Peter, > > Thank you for that code I found it very useful. One thing I > noticed which > I can't find documented anywhere ... > > > >> oformat.setDoctype(null, document.getDoctype().getSystemId()); > > I modified the line above to say > > > oformat.setDoctype(null, "file:/c:/temp/new.dtd"); > > It seems that if the document had no doctyope already defined > this works > okay BUT if it does then using the setDoctype does get used > (the original > DTD is retained). Can't find any note to this effect in the Javadoc. > > Do you know why this is or better still a way to override the > existing DTD > with the specified one? > > Cheers ... Dave > > P.S. I am using XML4J 3.0.1 based on Xerces 1.2.0 > > Dave Barfield > e-Business Integration Technology > IBM Hursley, MP 188, Hursley Park, Winchester, SO21 2JN, England > Phone: Internal 7-245131, external 44-1962-815131 > E-mail: [EMAIL PROTECTED] > > > > > > "Hellmann Peter > > > (ext) ICM RDC IS VDR To: > "'[EMAIL PROTECTED]'" > <[EMAIL PROTECTED]> > RD" cc: > > > <[EMAIL PROTECTED] Subject: > AW: Setting a DOCTYPE Declaration through DocumentType for a > bran d ne > siemens.de> w document > > > > > > 04/04/2002 14:59 > > > Please respond to > > > xerces-j-user > > > > > > > > > > > > setDoctype() does the job ! > > > /** > * Gets the xml > * > * @return the xml or "no valid document" > * @exception Standard exception "Exception" will be thrown > * > */ > > public String GetXml() > { > > if (null == document) > { > return "no valid document, cannot serialize DOM tree"; > } > > OutputFormat oformat = new OutputFormat(document); > > oformat.setDoctype(null, document.getDoctype().getSystemId()); > oformat.setLineWidth(80); > oformat.setIndent(2); > oformat.setLineSeparator("\r\n"); > oformat.setPreserveSpace(false); > oformat.setOmitComments(false); > oformat.setOmitDocumentType(false); > oformat.setOmitXMLDeclaration(false); > oformat.setEncoding(encType); > oformat.setVersion("1.0"); > oformat.setStandalone(true); > oformat.setIndenting(true); > oformat.setPreserveEmptyAttributes(true); > > StringWriter stringOut = new StringWriter(); > > try > { > > XMLSerializer serial = new XMLSerializer(stringOut, oformat); > serial.asDOMSerializer(); > > serial.serialize(document); > > } > catch (Exception e) > { > e.printStackTrace(System.err); > } > > return stringOut.toString(); > } > > > -----Urspr�ngliche Nachricht----- > > Von: Hand, Brian [mailto:[EMAIL PROTECTED] > > Gesendet: Mittwoch, 3. April 2002 23:45 > > An: '[EMAIL PROTECTED]' > > Betreff: Setting a DOCTYPE Declaration through DocumentType > > for a brand > > ne w document > > > > > > Hi all, > > > > Being somewhat a newbie to Xerces I would like a create a > > document (via a > > save function) and I would like to set the <!DOCTYPE .... > > statement in the > > document to be saved. I see that there are no setters in the > > DocumentType > > interface and was just wondering if someone could offer a > > quick snippet of > > code on how to set the <!DOCTYPE into the generated document. > > > > BTW I am using the DOM API. > > > > Thanks > > Brian > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
