Package de.odysseus.staxon.xml

Examples of de.odysseus.staxon.xml.SimpleXMLStreamWriter


   * <code>&lt;alice xmlns="http://some-namespace"&gt;bob&lt;/alice&gt;</code>
   */
  @Test
  public void testRepairNamespaces() throws Exception {
    StringWriter result = new StringWriter();
    XMLStreamWriter writer = new SimpleXMLStreamWriter(result, true);
    writer.writeStartDocument();
    writer.writeStartElement("http://some-namespace", "alice");
    writer.writeCharacters("bob");
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><alice xmlns=\"http://some-namespace\">bob</alice>", result.toString());
  }
View Full Code Here


    Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><alice xmlns=\"http://some-namespace\">bob</alice>", result.toString());
  }

  @Test(expected = XMLStreamException.class)
  public void testWriteElementMultipleRoots() throws XMLStreamException {
    XMLStreamWriter writer = new SimpleXMLStreamWriter(new StringWriter(), false);
    writer.writeStartElement("foo");
    writer.writeEndElement();
    writer.writeStartElement("foo");
  }
View Full Code Here

   * <code>&lt;alice&gt;&lt;bar:bob xmlns:bar="http://bar" jane="dolly"/&gt;hello&lt;/alice&gt;</code>
   */
  @Test
  public void testOther() throws XMLStreamException {
    StringWriter result = new StringWriter();
    XMLStreamWriter writer = new SimpleXMLStreamWriter(result, false);
    writer.setDefaultNamespace("http://foo");
    writer.writeStartDocument();
    writer.writeStartElement("alice");
    writer.writeEmptyElement("bar", "bob", "http://bar");
    writer.writeNamespace("bar", "http://bar");
    writer.writeAttribute("jane", "dolly");
    writer.writeCharacters("hello");
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><alice><bar:bob xmlns:bar=\"http://bar\" jane=\"dolly\"/>hello</alice>", result.toString());
  }
View Full Code Here

TOP

Related Classes of de.odysseus.staxon.xml.SimpleXMLStreamWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.