Java by API/javax.xml.stream/XMLStreamWriter

Материал из Java эксперт
Версия от 14:22, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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();
  }
}