2

I need to generate a node in a XML file with the following structure:

<node attribute0="value0" attribute1="value1" > </node>

How can I do it in StAX?

Edit 1: I'm trying the code from Section "3.4. Write XML File- Example" from Lars Vogel's tutorial (http://www.vogella.de/articles/JavaXML/article.html)

2
  • 3
    what code have you tried? what didn't work? Commented Jan 23, 2012 at 13:06
  • why not try his more advanced tutorial as recommended in the tutorial you have tried. vogella.de/articles/RSSFeed/article.html#write_stax Commented Jan 23, 2012 at 13:30

2 Answers 2

7

given the link you added it appears you use teh below syntax. have a look at his advanced tutorial for writting RSS feed here

StartElement rssStart = eventFactory.createStartElement("", "", "rss");
eventWriter.add(rssStart);
eventWriter.add(eventFactory.createAttribute("version", "2.0"));
eventWriter.add(end);
Sign up to request clarification or add additional context in comments.

Comments

4

If you would use XMLStreamWriter instead of the XMLEventWriter, you can do it the following way:

xmlStreamWriter.writeStartElement("node");
xmlStreamWriter.writeAttribute("attribute0","value0");
xmlStreamWriter.writeAttribute("attribute1","value1");
xmlStreamWriter.writeEndElement();

But also for XMLEventWriter, there is a Method to create Attributes:

xmlEventWriter.createAttribute(name, value);

Regards, Max

Comments

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.