You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Chris Gokey <cg...@hydrogen.stx.com> on 2000/07/26 15:24:29 UTC

XMLSerialize

Hi everyone,

I have been playing around with XmlSerialize, and here is a snippet of my code:

    private void writeXml(Writer writer, Document doc) throws java.io.IOException {
	OutputFormat o = new OutputFormat(doc);
	o.setIndenting(true);
	XMLSerializer s = new XMLSerializer(writer, o);
	s.asDOMSerializer(); // As a DOM Serializer
	s.serialize( doc.getDocumentElement() );
    }

My problem is this pretty prints a bit too much and adds newline characters to the
tag values.  I don't want this behavior, can I turn it off?  I tried doing this:
o.setLineWidth(0) and no longer attempted to add new lines, but removed all my
new lines inside each element!  How can I achieve nice indentation of the tags
and leave nside the tags alone?

Thanks,
Chris


-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov

Re: XMLSerialize

Posted by Chris Gokey <cg...@hydrogen.stx.com>.
Just an addition comment on XMLSerializer.  I have a XML structured used to hold
Personnel, i.e., it has elements like First_Name, Last_Name, Address, Fax, etc.  
With the writeXml code below, it prints XML for Personnel like this:

  <Personnel>
        <Role>Technical Contact</Role>
        <First_Name>YUKIO</First_Name>
        <Last_Name>HARUYAMA</Last_Name>
        <Phone>81-3-5470-4252</Phone>
        <Fax>81-3-3432-3969</Fax>
        <Address>      Program Planning and Management Department
            NASDA Head Office       Hamamatsu-cho       Minato-ku Tokyo
            105       Japan </Address>
    </Personnel>

Why does it remove the newlines from address?  I know for a fact that when I build the DOM,
I am including them.  Is this the best way to produce a neatly formatted XML from a DOM?  Is 
their something in Xalan maybe that would help?

I would very much appreciate a response on this.

Thanks
Chris


Chris Gokey wrote:
> 
> Hi everyone,
> 
> I have been playing around with XmlSerialize, and here is a snippet of my code:
> 
>     private void writeXml(Writer writer, Document doc) throws java.io.IOException {
>         OutputFormat o = new OutputFormat(doc);
>         o.setIndenting(true);
>         XMLSerializer s = new XMLSerializer(writer, o);
>         s.asDOMSerializer(); // As a DOM Serializer
>         s.serialize( doc.getDocumentElement() );
>     }
> 
> My problem is this pretty prints a bit too much and adds newline characters to the
> tag values.  I don't want this behavior, can I turn it off?  I tried doing this:
> o.setLineWidth(0) and no longer attempted to add new lines, but removed all my
> new lines inside each element!  How can I achieve nice indentation of the tags
> and leave nside the tags alone?
> 
> Thanks,
> Chris
> 
> --
> Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
> 18 Martin Road, Shelburne Falls, MA  01370
> Phone: Voice (413) 625-8129 / FAX 208-248-9055
> cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
> 
> 

-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov