本文整理匯總了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());
}