cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Re: Xercess
Date Thu, 20 Jul 2000 09:02:16 GMT
At 09:57 -0300 19/07/00, Martin O. Mauri wrote:
>Hi people.
>
>I'm trying to build an application with Xerces parser and I faced with this
>problem:
>
>I have to parse an XML file with DOM and walk through the tree modifying
>some elements...
>But afterwards, I have to store the file with the modifications I've
>made...how does DOM work?
>It erases the file and creates it again?

that is up to you

>or replaces the the nodes I've changed and then modifies the files in the
>disc?

Have a look at the source for XMLForm Servlet or FP TagLib,

>can you send me any example?

	this is from FP TagLib

	workDoc is the DOM object, workFile is a File object

	public void save(Node cNode, Hashtable errors) {
		OutputFormat format = new OutputFormat(workDoc, workEncoding, true);
		// dunno which of these is required
		format.setVersion("1.0");
		format.setPreserveSpace(true);
		format.setIndent(1);
		format.setIndenting(true);
		format.setLineWidth(0);
		format.setLineSeparator("\n");

		try {
			FileWriter writer = new FileWriter(workFile);
			Serializer serializer = serializer_factory.makeSerializer(writer,format);
			serializer.asDOMSerializer().serialize(workDoc);
			writer.close();
		} catch (Exception ex) {
			fpLibrary.reportError(cNode, cNode, errors, "Cannot save the file: "
+ workFile);
			ex.printStackTrace();
		}
	}


hope this helps

Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <mailto:sharkbait@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pager:jermq@sms.genie.co.uk>

Mime
View raw message