Java Reference
In-Depth Information
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
class StAXDemo
{
public static void main(String[] args)
{
try
{
XMLOutputFactory
xmlof
=
XMLOutputFact-
ory.newFactory();
XMLStreamWriter xmlsw;
xmlsw
=
xmlof.createXMLStreamWriter(new
FileWriter("recipe.xml"));
xmlsw.writeStartDocument();
xmlsw.setPrefix("h",
"http://www.w3.org/1999/
xhtml");
xmlsw.writeStartElement("http://www.w3.org/1999/
xhtml", "html");
xmlsw.writeNamespace("h",
"http://www.w3.org/
1999/xhtml");
xmlsw.writeNamespace("r",
"ht-
tp://www.tutortutor.ca/");
xmlsw.writeStartElement("http://www.w3.org/1999/
xhtml", "head");
xmlsw.writeStartElement("http://www.w3.org/1999/
xhtml", "title");
xmlsw.writeCharacters("Recipe");
xmlsw.writeEndElement();
xmlsw.writeEndElement();
xmlsw.writeStartElement("http://www.w3.org/1999/
xhtml", "body");
xmlsw.setPrefix("r",
"http://www.tutortutor.ca/
");
Search WWH ::




Custom Search