DRastislav
DRastislav

Reputation: 1882

Java and XML output

I have a question about output in XML. I have scanner for 1st and 2nd number... And i would like to prepare xml output file with form (e.g 1st number is 10, 2nd is 15)

<line>
    <Point>
        <X>10</X>
    </Point>
</line>
<line>
    <Point>
         <X>11</X>
    </Point>
</line>

<line>
    <Point>
       <X>12</X>
    </Point>
</line>

and so on ... till second number

try{


               XMLOutputFactory f = XMLOutputFactory.newInstance();
               XMLStreamWriter w = f.createXMLStreamWriter(new FileOutputStream(output));

               w.writeComment("XMLOutput");


               w.writeStartElement("line");
               w.writeStartElement("Point");
               w.writeStartElement("X");
              String pointX0 = String.valueOf(a);
               w.writeCharacters(pointX0);
              w.writeEndElement();



              w.writeEndElement();

               }
               w.writeEndElement();
               w.writeEndDocument();
               w.close();
                } catch (XMLStreamException ex) {
                    Logger.getLogger(Output.class.getName()).log(Level.SEVERE, null, ex);
                }
    }

Iam Struggling with for loop but I dont know where shall i put it ...

Upvotes: 0

Views: 83

Answers (1)

user785262
user785262

Reputation:

Try using XStream http://x-stream.github.io/ to serialize the XML you need from POJOs.

Upvotes: 1

Related Questions