List of usage examples for javax.xml.stream XMLOutputFactory createXMLStreamWriter
public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(System.out); xsw.writeStartDocument();/*from www . j a v a2 s . co m*/ xsw.writeStartElement("response"); xsw.writeStartElement("message"); xsw.writeCharacters("1 < 2"); xsw.writeEndDocument(); xsw.close(); }
From source file:EmptyElement.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeEmptyElement("empty"); writer.writeAttribute("attribute", "true"); writer.writeEndDocument();// w w w .j a v a 2s .c o m writer.flush(); // write /> to the console }
From source file:MainClass.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("person"); writer.writeStartElement("name"); writer.writeStartElement("fname"); writer.writeCharacters("AAA"); writer.writeEndDocument();/*from www .j a v a2 s. c o m*/ writer.flush(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartElement("ns1", "sample", "http://www.e.com/ns1"); writer.writeNamespace("ns1", "http://www.e.com/ns1"); writer.writeAttribute("http://www.e.com/ns2", "attribute", "true"); writer.writeEmptyElement("http://www.e.com/ns1", "inner"); writer.writeEmptyElement("ns2", "inner", "http://www.e.com/ns2"); writer.writeEndElement();//from w w w . ja v a 2 s. c o m writer.writeEndDocument(); writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.setDefaultNamespace("http://www.example.com/ns1"); writer.writeStartElement("http://www.example.com/ns1", "sample"); writer.writeDefaultNamespace("http://www.example.com/ns1"); writer.writeEmptyElement("inner"); writer.setDefaultNamespace("http://www.example.com/ns2"); writer.writeStartElement("http://www.example.com/ns2", "inner2"); writer.writeDefaultNamespace("http://www.example.com/ns2"); writer.writeNamespace("ns1", "http://www.example.com/ns1"); writer.writeEmptyElement("http://www.example.com/ns1", "inner"); writer.writeEndDocument();/* ww w . j a va 2s .co m*/ writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeCharacters("\n"); writer.writeStartElement("ns1", "sample", "http://www.e.com/ns1"); writer.writeNamespace("ns1", "http://www.e.com/ns1"); writer.writeEmptyElement("http://www.e.com/ns1", "inner1"); writer.writeAttribute("otherAttribute", "true"); writer.writeEndElement();// w ww. ja v a2 s . c om writer.writeEndDocument(); writer.flush(); System.out.println(); }
From source file:Main.java
public static void main(String[] args) throws Exception { OutputStream stream = System.out; XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(stream); xsw.writeStartDocument();//from w ww . j a v a2s . c om xsw.writeStartElement("foo"); xsw.writeStartElement("bar"); xsw.writeCharacters(""); xsw.flush(); OutputStreamWriter osw = new OutputStreamWriter(stream); osw.write("<baz>Hello World<baz>"); osw.flush(); xsw.writeEndElement(); xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("addresses"); writer.writeStartElement("address"); writer.writeAttribute("type", "work"); writer.writeStartElement("street"); writer.writeCharacters("1111 Ave"); writer.writeComment("comments"); writer.writeEndElement();//from ww w. j a v a2 s . c om writer.writeEmptyElement("inner"); writer.flush(); System.out.println(); writer.writeAttribute("otherAttribute", "true"); writer.flush(); System.out.println(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("catalog"); writer.writeStartElement("book"); writer.writeAttribute("id", "1"); writer.writeStartElement("code"); writer.writeCharacters("I01"); writer.writeEndElement();/*w ww . j a v a 2 s. c om*/ writer.writeStartElement("title"); writer.writeCharacters("This is the title"); writer.writeEndElement(); writer.writeStartElement("price"); writer.writeCharacters("$2.95"); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); }
From source file:CursorWriter.java
public static void main(String[] args) throws Exception { String fileName = "yourXML.xml"; XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null;/*from ww w. j a v a2 s . c om*/ xtw = xof.createXMLStreamWriter(new FileWriter(fileName)); xtw.writeComment("all elements here are explicitly in the HTML namespace"); xtw.writeStartDocument("utf-8", "1.0"); xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "html"); xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "head"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "title"); xtw.writeCharacters("character"); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "body"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "p"); xtw.writeCharacters("another character"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "a"); xtw.writeAttribute("href", "http://www.java2s.com"); xtw.writeCharacters("here"); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndDocument(); xtw.flush(); xtw.close(); System.out.println("Done"); }