Java by API/javax.xml.stream/XMLStreamWriter
Содержание
- 1 XMLStreamWriter: flush()
- 2 XMLStreamWriter: writeAttribute(String localName, String value)
- 3 XMLStreamWriter: writeEmptyElement(String localName)
- 4 XMLStreamWriter: writeEmptyElement(String namespaceURI, String localName)
- 5 XMLStreamWriter: writeEndDocument()
- 6 XMLStreamWriter: writeEndElement()
- 7 XMLStreamWriter: writeNamespace(String prefix, String namespaceURI)
- 8 XMLStreamWriter: writeStartDocument(String version)
- 9 XMLStreamWriter: writeStartElement(String prefix, String localName, String namespaceURI)
XMLStreamWriter: flush()
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeAttribute(String localName, String value)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeEmptyElement(String localName)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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();
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();
}
}
XMLStreamWriter: writeEmptyElement(String namespaceURI, String localName)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeEndDocument()
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeEndElement()
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeNamespace(String prefix, String namespaceURI)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeStartDocument(String version)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}
XMLStreamWriter: writeStartElement(String prefix, String localName, String namespaceURI)
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
public class Main {
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.ru/ns1");
writer.writeNamespace("ns1", "http://www.e.ru/ns1");
writer.writeEmptyElement("http://www.e.ru/ns1", "inner1");
writer.writeAttribute("otherAttribute", "true");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
System.out.println();
}
}