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 tom john <cy...@yahoo.com> on 2002/02/18 16:06:14 UTC

serielizing node

hi,

i am trying to convert a node to string. i am using
the following code


ByteArrayOutputStream out = new
ByteArrayOutputStream();
try{
  Transformer t =
TransformerFactory.newInstance().newTransformer();
  t.transform(new DOMSource(node), new
StreamResult(out));
}catch....

String xmlString = out.toString();

it works fine without a problem. but it adds xml
heading. eg. if i have a node <node1>abcd</node1>

it creates String
<?xml version="1.0" encoding="UTF-8"?>
<node1>abcd</node1>

i need to create string as '<node1>abcd</node1>'.

how is it possible?

thanks

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

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


Re: serielizing node

Posted by Arturo Ma <am...@fgm.com>.
Tom John:

You just need to set the transformer property accordingly before you perform
the transformation
as follows:

import javax.xml.transform.OutputKeys;

> ByteArrayOutputStream out = new
> ByteArrayOutputStream();
> try{
>   Transformer t =
> TransformerFactory.newInstance().newTransformer();
     t.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes");
>   t.transform(new DOMSource(node), new
> StreamResult(out));
> }catch....
>
> String xmlString = out.toString();
>

Hope this helps.

-------------------------------------------------------------
Arturo Ma
ama@fgm.com
FGM Inc.
2820 Camino Del Rio South, Suite 130
San Diego, CA 92108
Office: 619. 297.2905
Fax: 619. 297.2923
http://www.fgm.com


----- Original Message -----
From: "tom john" <cy...@yahoo.com>
To: <xe...@xml.apache.org>
Sent: Monday, February 18, 2002 7:06 AM
Subject: serielizing node


> hi,
>
> i am trying to convert a node to string. i am using
> the following code
>
>
> ByteArrayOutputStream out = new
> ByteArrayOutputStream();
> try{
>   Transformer t =
> TransformerFactory.newInstance().newTransformer();
>   t.transform(new DOMSource(node), new
> StreamResult(out));
> }catch....
>
> String xmlString = out.toString();
>
> it works fine without a problem. but it adds xml
> heading. eg. if i have a node <node1>abcd</node1>
>
> it creates String
> <?xml version="1.0" encoding="UTF-8"?>
> <node1>abcd</node1>
>
> i need to create string as '<node1>abcd</node1>'.
>
> how is it possible?
>
> thanks
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - Coverage of the 2002 Olympic Games
> http://sports.yahoo.com
>
> ---------------------------------------------------------------------
> 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