Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to a create well-formed .xml File out of a DOM document..
How to a create well-formed .xml File out of a DOM document.. [message #67002] Fri, 20 May 2005 12:42 Go to next message
Eclipse UserFriend
Originally posted by: moserm.de.ibm.com

This is a multipart message in MIME format.
--=_alternative 0045A419C1257007_=
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi out there..=20

im sure one of u guys could help me ; )=20

I=B4ve got a .xml File and parse it with the DocumentBuilder.=20
On the resulting DOMdocument, i add some Attributes and Childnodes. ..so=20
far.
=20
Now i want to overwrite the sourcefile:=20

<code>
Document document =3D parser.parseFile(path);
=20
try {
=20
Transformer transformer =3D TransformerFactory.newInstance()=20
newTransformer();
DOMSource source =3D new DOMSource(document);
FileOutputStream os =3D new FileOutputStream(new File(path +=20
"/plugin.xml"));
StreamResult result =3D new StreamResult(os);
transformer.transform(source, result);

} catch (Exception e) {
e.printStackTrace();
}//end try-catch
</code>

it works.... all the changes are written in the xml file, but the new tag=20
and all its attribs and childs are written in a single line!=20

I don=B4t get it...=20
I=B4ve checked the Transformer-, DOMSource-,FileOututStream- and the=20
StreamResult - API, but haven=B4t found a parameter which set the output as=
=20
well-formed.=20
For sure it is valid xml, but it isn=B4t nice..=20

thx for Help=20

Greetz=20
Manuel

--=_alternative 0045A419C1257007_=
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable


<br><font size=3D2 face=3D"sans-serif">Hi out there.. </font>
<br>
<br><font size=3D2 face=3D"sans-serif">im sure one of u guys could help me
; ) </font>
<br>
<br><font size=3D2 face=3D"sans-serif">I=B4ve got a .xml File and parse it =
with
the DocumentBuilder. </font>
<br><font size=3D2 face=3D"sans-serif">On the resulting DOMdocument, i add
some Attributes and Childnodes. ..so far.</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp;</font>
<br><font size=3D2 face=3D"sans-serif">Now i want to overwrite the sourcefi=
le:
</font>
<br>
<br><font size=3D2 face=3D"sans-serif">&lt;code&gt;</font>
<br><font size=3D2 face=3D"sans-serif">Document document =3D parser.parseFi=
le(path);</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; </font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; try {</f=
ont>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; </font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
Transformer transformer =3D TransformerFactory.newInstance() .newTransforme=
r();</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
DOMSource source =3D new DOMSource(document);</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
FileOutputStream os =3D new FileOutputStream(new File(path + &quot;/plugin.=
xml&quot;));</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
StreamResult result =3D new StreamResult(os);</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
transformer.transform(source, result);</font>
<br>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; } catch
(Exception e) {</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp;
e.printStackTrace();</font>
<br><font size=3D2 face=3D"sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; }//end t=
ry-catch</font>
<br><font size=3D2 face=3D"sans-serif">&lt;/code&gt;</font>
<br>
<br><font size=3D2 face=3D"sans-serif">it works.... all the changes are wri=
tten
in the xml file, but the new tag and all its attribs and childs are written
in a single line! </font>
<br>
<br><font size=3D2 face=3D"sans-serif">I don=B4t get it... </font>
<br><font size=3D2 face=3D"sans-serif">I=B4ve checked the Transformer-, DOM=
Source-,FileOututStream-
and the StreamResult - API, but haven=B4t found a parameter which set the
output as well-formed. </font>
<br><font size=3D2 face=3D"sans-serif">For sure it is valid xml, but it isn=
=B4t
nice.. </font>
<br>
<br><font size=3D2 face=3D"sans-serif">thx for Help </font>
<br>
<br><font size=3D2 face=3D"sans-serif">Greetz </font>
<br><font size=3D2 face=3D"sans-serif">Manuel</font>
<br>
--=_alternative 0045A419C1257007_=--
Re: How to a create well-formed .xml File out of a DOM document.. [message #67062 is a reply to message #67002] Fri, 20 May 2005 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: moserm.de.ibm.com

This is a multipart message in MIME format.
--=_alternative 004EC1CDC1257007_=
Content-Type: text/plain; charset="US-ASCII"

sorry, i used the wrong expression..

the output xml file ist of course well-formed.

what i ment is that the added Nodes are not formatted. (pretty print)

so is there a way in DOM or have i to parse the file with SAX / JDOM ?

thx

Manuel


--=_alternative 004EC1CDC1257007_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">sorry, i used the wrong expression..
</font>
<br>
<br><font size=2 face="sans-serif">the output xml file ist of course well-formed.
</font>
<br>
<br><font size=2 face="sans-serif">what i ment is that the added Nodes
are not formatted. (pretty print)</font>
<br>
<br><font size=2 face="sans-serif">so is there a way in DOM or have i to
parse the file with SAX / JDOM ? </font>
<br>
<br><font size=2 face="sans-serif">thx </font>
<br>
<br><font size=2 face="sans-serif">Manuel</font>
<br>
<br>
--=_alternative 004EC1CDC1257007_=--
Re: How to a create well-formed .xml File out of a DOM document.. [message #71730 is a reply to message #67062] Tue, 31 May 2005 19:48 Go to previous messageGo to next message
David Bowen is currently offline David BowenFriend
Messages: 8
Registered: July 2009
Junior Member
moserm@de.ibm.com wrote:

> sorry, i used the wrong expression..
>
> the output xml file ist of course well-formed.
>
> what i ment is that the added Nodes are not formatted. (pretty print)
>
> so is there a way in DOM or have i to parse the file with SAX / JDOM ?
>
> thx
>
> Manuel

I'll admit I am using Xalan to achieve this as I couldn't see how to do it
using the built-in libraries. I had to wrap the Xalan jar file in a plug-in
so that I could reference it, but since then it's being doing a fantastic
job (even with Japanese).

David Bowen
Re: How to a create well-formed .xml File out of a DOM document.. [message #71749 is a reply to message #71730] Tue, 31 May 2005 19:54 Go to previous messageGo to next message
Philippe Ombredanne is currently offline Philippe OmbredanneFriend
Messages: 386
Registered: July 2009
Senior Member
Use Xom :-)


"David Bowen" <David@MyForest.Com> wrote in message
news:d7ifbh$5vl$1@news.eclipse.org...
> moserm@de.ibm.com wrote:
>
> > sorry, i used the wrong expression..
> >
> > the output xml file ist of course well-formed.
> >
> > what i ment is that the added Nodes are not formatted. (pretty print)
> >
> > so is there a way in DOM or have i to parse the file with SAX / JDOM ?
> >
> > thx
> >
> > Manuel
>
> I'll admit I am using Xalan to achieve this as I couldn't see how to do it
> using the built-in libraries. I had to wrap the Xalan jar file in a
plug-in
> so that I could reference it, but since then it's being doing a fantastic
> job (even with Japanese).
>
> David Bowen
Re: How to a create well-formed .xml File out of a DOM document.. [message #71767 is a reply to message #71749] Tue, 31 May 2005 20:50 Go to previous messageGo to next message
David Bowen is currently offline David BowenFriend
Messages: 8
Registered: July 2009
Junior Member
Thanks Philippe, I can see Xom is only about 100KiB whereas our Xalan
plug-in is about 800KiB. In my case I may as well go with Xalan as existing
components are already using (and shipping) it.

Vive la difference.

David


Philippe Ombredanne wrote:

> Use Xom :-)
> >> I'll admit I am using Xalan to achieve this as I couldn't see how to do
>> it using the built-in libraries. I had to wrap the Xalan jar file in a
> plug-in
>> so that I could reference it, but since then it's being doing a fantastic
>> job (even with Japanese).
>>
>> David Bowen
Re: How to a create well-formed .xml File out of a DOM document.. [message #71899 is a reply to message #71767] Wed, 01 June 2005 12:13 Go to previous message
Eclipse UserFriend
Originally posted by: moserm.de.ibm.com

This is a multipart message in MIME format.
--=_alternative 0042A0EBC1257013_=
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

Well..=20

thx for all the Help!=20
But i=B4ve solved the problem allready,=20

I used an XMLSerializer and an OutputFormat.=20
The OutputFormat has the method .setIntend(x), which allows u to assign=20
the width of each break.=20

Both are included in Eclipse 3.0.2 .=20

Greetz
Manuel
--=_alternative 0042A0EBC1257013_=
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable


<br><font size=3D2 face=3D"sans-serif">Well.. </font>
<br>
<br><font size=3D2 face=3D"sans-serif">thx for all the Help! </font>
<br><font size=3D2 face=3D"sans-serif">But i=B4ve &nbsp;solved the problem =
allready,
</font>
<br>
<br><font size=3D2 face=3D"sans-serif">I used an XMLSerializer and an Outpu=
tFormat.
</font>
<br><font size=3D2 face=3D"sans-serif">The OutputFormat &nbsp;has the method
setIntend(x), which allows u to assign the width of each break. </font>
<br>
<br><font size=3D2 face=3D"sans-serif">Both are included in Eclipse 3.0.2 .
</font>
<br>
<br><font size=3D2 face=3D"sans-serif">Greetz</font>
<br><font size=3D2 face=3D"sans-serif">Manuel</font>
--=_alternative 0042A0EBC1257013_=--
Previous Topic:tiny menu font size in KDE
Next Topic:java documentation
Goto Forum:
  


Current Time: Fri Aug 23 12:25:01 GMT 2024

Powered by FUDForum. Page generated in 0.39427 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top