本文整理汇总了Java中javax.xml.stream.XMLEventFactory.createComment方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEventFactory.createComment方法的具体用法?Java XMLEventFactory.createComment怎么用?Java XMLEventFactory.createComment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLEventFactory
的用法示例。
在下文中一共展示了XMLEventFactory.createComment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetLocation
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@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);
}
示例2: testEvents
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@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());
}
}
示例3: testNonNullLocation
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Test
public void testNonNullLocation() {
XMLEventFactory factory = XMLEventFactory.newInstance();
XMLEvent event = factory.createComment("some comment");
Assert.assertNotNull(event.getLocation());
}