You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Martin O. Mauri" <mm...@vates.com> on 2000/07/19 14:57:44 UTC

Xercess

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?
or replaces the the nodes I've changed and then modifies the files in the
disc?

can you send me any example?

thanks in advance.

Lic. Martin O. Mauri
mmauri@vates.com
mmauri@ubp.edu.ar
Vates S.A. IngenierĂ­a de Software
Tel/Fax: (0351)-4240133


Re: Xercess

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
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

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pa...@sms.genie.co.uk>