List of usage examples for javax.xml.stream XMLStreamWriter flush
public void flush() throws XMLStreamException;
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 ww . ja va 2 s . c o m writer.flush(); // write /> to the console }
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();/*w ww .j a v a 2 s. c o m*/ 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: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 w w w . ja va2 s . com writer.flush(); }
From source file:MainClass.java
public static void main(String[] args) throws XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("http://www.t.com/f", "sample"); writer.writeAttribute("attribute", "true"); writer.writeAttribute("http://www.t.com/f", "attribute2", "false"); writer.writeCharacters("some text"); writer.writeCData("<test>"); writer.writeEndElement();/*from w ww . j a va2 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.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 w w w .j a v a2 s. c o m*/ 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 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();/*from w w w .j ava 2s .c om*/ writer.writeEndDocument(); writer.flush(); System.out.println(); }
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();/*ww w . j ava 2 s .c o m*/ 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();//from w w w . j av a 2 s. c o m 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: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();/*from w w w . j ava 2 s . c om*/ writer.flush(); }
From source file:CursorWriter.java
public static void main(String[] args) throws Exception { String fileName = "yourXML.xml"; XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null; 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();//ww w . j a v a2s. c om 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"); }