0

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 ...

2
  • Improving your grammar and the description of your problem will help you get answers faster. Commented Dec 2, 2012 at 15:52
  • sorry m8s ... I Have two numbers (user´s input) and i Would like to create output as u can see above Commented Dec 2, 2012 at 15:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@DRastislav - Also consider a JAXB (JSR-222) implementation. One is included in the JDK/JRE: blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-xstream.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.