user3364281
user3364281

Reputation: 47

How to write XML tags by using BufferedWriter

I tried to write xml tags by using BufferWriterBut,when i am trying to open a file it is displaying like empty page.The code is like below

bw.write("<?xml version=" + "\"1.0\"" + " " + "encoding=" + "\"UTF-8\""
                + "?>");
        bw.newLine();
        bw.write("<con:soapui-project activeEnvironment=" + "\"Default\"" + " "
                + " name=" + "\"REST Project 1\"" + " " + "soapui-version="
                + "\"4.6.4\"" + " " + "xmlns:con="
                + "\"http://eviware.com/soapui/config\"" + ">");
        bw.newLine();
        bw.write("<con:settings/>");
        bw.newLine();
        bw.write("<con:interface xsi:type=" + "\"con:RestService\"" + " "
                + "wadlVersion=" + "\"http://wadl.dev.java.net/2009/02\"" + " "
                + "name=" + "\"" + baseUrl1 + "\"" + "" + " " + "type="
                + "\"rest\"" + " " + "xmlns:xsi="
                + "\"http://www.w3.org/2001/XMLSchema-instance\"" + ">");
        bw.newLine();
        bw.write("<con:settings/>");

Can i write the xml tags like above or is there any way to write xml tags

Upvotes: 0

Views: 976

Answers (4)

Ravi Gawas
Ravi Gawas

Reputation: 1

Use Documentbuilder Class instead. It has Element interface which can be used to write xml tags more efficiently.

Upvotes: 0

Rey Libutan
Rey Libutan

Reputation: 5314

Why reinvent the wheel? You could use JAXB and search for marshalling.

For starters you could refer to this.

Upvotes: 2

Klemens Morbe
Klemens Morbe

Reputation: 653

If JAXB is to difficult for you, try the DOM Parser. Its pretty simple.

DOM Example

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328724

A BufferWriter, as the name implies, has a buffer and it will only flush the buffer to the file when one of three conditions are met:

  1. The buffer is full
  2. You flush the buffer manually calling flush()
  3. The writer is closed

None of them apply in your case, so the file stays empty.

Upvotes: 1

Related Questions