How to a create well-formed .xml File out of a DOM document.. [message #67002] |
Fri, 20 May 2005 12:42 |
Eclipse User |
|
|
|
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"> </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"><code></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"> </font>
<br><font size=3D2 face=3D"sans-serif"> try {</f=
ont>
<br><font size=3D2 face=3D"sans-serif"> </font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
Transformer transformer =3D TransformerFactory.newInstance() .newTransforme=
r();</font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
DOMSource source =3D new DOMSource(document);</font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
FileOutputStream os =3D new FileOutputStream(new File(path + "/plugin.=
xml"));</font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
StreamResult result =3D new StreamResult(os);</font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
transformer.transform(source, result);</font>
<br>
<br><font size=3D2 face=3D"sans-serif"> } catch
(Exception e) {</font>
<br><font size=3D2 face=3D"sans-serif"> &=
nbsp;
e.printStackTrace();</font>
<br><font size=3D2 face=3D"sans-serif"> }//end t=
ry-catch</font>
<br><font size=3D2 face=3D"sans-serif"></code></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 |
Eclipse User |
|
|
|
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 #71899 is a reply to message #71767] |
Wed, 01 June 2005 12:13 |
Eclipse User |
|
|
|
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 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 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_=--
|
|
|
Powered by
FUDForum. Page generated in 0.09022 seconds