Java Code Examples for javax.xml.stream.XMLEventFactory#createComment()

The following examples show how to use javax.xml.stream.XMLEventFactory#createComment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLEventLocationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSetLocation() {
    XMLEventFactory factory = XMLEventFactory.newInstance();
    Location loc = new MyLocation();
    factory.setLocation(loc);
    XMLEvent event = factory.createComment("some comment");
    Assert.assertEquals(event.getLocation().getLineNumber(), 15);
}
 
Example 2
Source File: Issue41Test.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testEvents() {
    XMLEventFactory f = XMLEventFactory.newInstance();
    final String contents = "test <some> text & more! [[]] --";
    final String prefix = "prefix";
    final String uri = "http://foo";
    final String localName = "elem";

    try {
        StartDocument sd = f.createStartDocument();
        writeAsEncodedUnicode(sd);

        Comment c = f.createComment("some comments");
        writeAsEncodedUnicode(c);

        StartElement se = f.createStartElement(prefix, uri, localName);

        ProcessingInstruction pi = f.createProcessingInstruction("target", "data");
        writeAsEncodedUnicode(pi);

        Namespace ns = f.createNamespace(prefix, uri);
        writeAsEncodedUnicode(ns);

        Characters characters = f.createCharacters(contents);
        writeAsEncodedUnicode(characters);
        // CData
        Characters cdata = f.createCData(contents);
        writeAsEncodedUnicode(cdata);

        // Attribute
        QName attrName = new QName("http://test.com", "attr", "ns");
        Attribute attr = f.createAttribute(attrName, "value");
        writeAsEncodedUnicode(attr);

        // prefix, uri, localName
        EndElement ee = f.createEndElement(prefix, uri, localName);
        writeAsEncodedUnicode(ee);

        EndDocument ed = f.createEndDocument();
        writeAsEncodedUnicode(ed);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }

}
 
Example 3
Source File: XMLEventLocationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testNonNullLocation() {
    XMLEventFactory factory = XMLEventFactory.newInstance();
    XMLEvent event = factory.createComment("some comment");
    Assert.assertNotNull(event.getLocation());
}