You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Li Liang <ll...@firstrain.com> on 2001/07/16 18:15:54 UTC

How to serialize a DOM document

A dumb question: How can I serialize a DOM document into an XML file.
Thanks.

Li


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Schema not found

Posted by Armin Mueller <Da...@web.de>.
I have a schema which includes another schema. Xerces doesn't find the 
included schema, if the schema files und the xml file are in different 
directories. What can I do? I know I asked the same question a few days ago, 
but there was no answer. I really need a solution to the problem.

Thank you in advance
Armin


On Tuesday 17 July 2001 05:02, I wrote:
> I've the same problems with relative schema paths as David NeSmith
> described.
>
> My file structure is:
> example.xml
> xsd/ML.xsd
> xsd/ML_primitive.xsd
>
> in example.xml the xsi:schemaLocation attribut has the relative path
> xsd/ML.xsd.
> In ML.xsd is a include tag which shows to ML_primitive.xsd without the
> path xsd. Xerces can't find this file and I get following errors:
>
> [Warning] :0:0: File "file:///home/dave/tmp/ML_primitive.xsd" not found.
> [Error] example.xml:5:74: Schema error: Element bool not found in the
> Schema.
> [Error] example.xml:5:74: Schema error: Element int not found in the
> Schema. [Error] example.xml:5:74: Schema error: Element real not found in
> the Schema.
> [Error] example.xml:5:74: Schema error: Element string not found in the
> Schema.
> [Error] example.xml:7:25: Element type "string" must be declared.
> [Error] example.xml:7:25: Attribute "value" must be declared for element
> type "string".
>
> Why does Xerces search for ML_primitive.xsd relative to the directory of
> the xml file and not relative to the directory of the xsd-file where the
> include tag is used?
>
> Thanks,
> Armin

Re: Question regarding schema paths...

Posted by Armin Müller <da...@web.de>.
I've the same problems with relative schema paths as David NeSmith 
described.

My file structure is:
example.xml
xsd/ML.xsd
xsd/ML_primitive.xsd

in example.xml the xsi:schemaLocation attribut has the relative path 
xsd/ML.xsd.
In ML.xsd is a include tag which shows to ML_primitive.xsd without the 
path xsd. Xerces can't find this file and I get following errors:

[Warning] :0:0: File "file:///home/dave/tmp/ML_primitive.xsd" not found.
[Error] example.xml:5:74: Schema error: Element bool not found in the 
Schema.
[Error] example.xml:5:74: Schema error: Element int not found in the Schema.
[Error] example.xml:5:74: Schema error: Element real not found in the 
Schema.
[Error] example.xml:5:74: Schema error: Element string not found in the 
Schema.
[Error] example.xml:7:25: Element type "string" must be declared.
[Error] example.xml:7:25: Attribute "value" must be declared for element 
type "string".

Why does Xerces search for ML_primitive.xsd relative to the directory of 
the xml file and not relative to the directory of the xsd-file where the 
include tag is used?

Thanks,
Armin

Re: How to serialize a DOM document

Posted by Zhaohua Meng <me...@hotlens.com>.
Look at org.apache.xml.serialize package. There are some serializers 
for you to chose for different output format, such as html and xhtml. 
In your case, construct a XMLSerializer like the following:

Document yourDocument;//populate with your input file.
OutputFormat format = new OutputFormat();
//here you can do something about format according your need, such
//as disabling the output of "DOCTYPE".

OutputStream file = new FileOutputStream("yourOutputFile");
XMLSerializer s = new org.apache.xml.serialize.XMLSerializer(file, 
format);
s.serialize(yourDocument);

Good luck.

Zhaohua Meng

Hotlens.com Inc.
http://www.hotlens.com

350 Fifth AVE
Suite 3113
New York, NY 10118
Phone: 212-465-1700
Fax:   212-465-1710
email: mengzh@hotlens.com


-----Original Message-----
From: "Li Liang" <ll...@firstrain.com>
To: <xe...@xml.apache.org>
Date: Mon, 16 Jul 2001 12:15:54 -0400
Subject: How to serialize a DOM document

> A dumb question: How can I serialize a DOM document into an XML file.
> Thanks.
> 
> Li
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: How to serialize a DOM document

Posted by Christian Geuer-Pollmann <ma...@nue.et-inf.uni-siegen.de>.
> A dumb question: How can I serialize a DOM document into an XML file.

import java.io.FileOutputStream;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;




Mit freundlichen Grüßen,

Christian Geuer-Pollmann


--------------------------------------------------------------------------
Institute for Data Communications Systems             University of Siegen
Hoelderlinstrasse 3                 D-57068 Siegen                 Germany

mail:  mailto:geuer-pollmann@nue.et-inf.uni-siegen.de
web:  <http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/>

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: How to serialize a DOM document

Posted by Christian Geuer-Pollmann <ma...@nue.et-inf.uni-siegen.de>.
/*
> A dumb question: How can I serialize a DOM document into an XML file.

Sorry, forgot the rest:
*/

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;


Element contextNode = ...; // create Element here

OutputStream os = new FileOutputStream(filename);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(contextNode);
StreamResult result = new StreamResult(os);

transformer.transform(source, result);



// Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org