本文整理汇总了Java中javax.xml.stream.XMLEventFactory.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEventFactory.newInstance方法的具体用法?Java XMLEventFactory.newInstance怎么用?Java XMLEventFactory.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLEventFactory
的用法示例。
在下文中一共展示了XMLEventFactory.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateStartDocument_DOMWriter
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
/**
* @bug 8139584
* Verifies that the resulting XML contains the standalone setting.
*/
@Test
public void testCreateStartDocument_DOMWriter()
throws ParserConfigurationException, XMLStreamException {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
eventWriter.add(event);
eventWriter.flush();
Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
Assert.assertEquals(doc.getXmlVersion(), "1.0");
Assert.assertTrue(doc.getXmlStandalone());
}
示例2: testCreateStartDocument
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
/**
* @bug 8139584
* Verifies that the resulting XML contains the standalone setting.
*/
@Test
public void testCreateStartDocument() throws XMLStreamException {
StringWriter stringWriter = new StringWriter();
XMLOutputFactory out = XMLOutputFactory.newInstance();
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEventWriter eventWriter = out.createXMLEventWriter(stringWriter);
XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
eventWriter.add(event);
eventWriter.flush();
Assert.assertTrue(stringWriter.toString().contains("encoding=\"iso-8859-15\""));
Assert.assertTrue(stringWriter.toString().contains("version=\"1.0\""));
Assert.assertTrue(stringWriter.toString().contains("standalone=\"yes\""));
}
示例3: createNode
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
// Create Start node
StartElement sElement = eventFactory.createStartElement("", "", name);
eventWriter.add(tab);
eventWriter.add(sElement);
// Create Content
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
// Create End node
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
eventWriter.add(end);
}
示例4: createNode
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
StartElement sElement = eventFactory.createStartElement("", "", name);
eventWriter.add(tab);
eventWriter.add(sElement);
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
eventWriter.add(end);
}
示例5: createNode
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
// Create start node
StartElement sElement = eventFactory.createStartElement("", "", name);
eventWriter.add(tab);
eventWriter.add(sElement);
// Create Content
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
// Create End node
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
eventWriter.add(end);
}
示例6: createNode
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
// Create Start node
StartElement sElement = eventFactory.createStartElement("", "", name);
eventWriter.add(tab);
eventWriter.add(sElement);
// Create Content
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
// Create End node
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
eventWriter.add(end);
}
示例7: createNode
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
private void createNode(XMLEventWriter eventWriter, String name,
String value) throws XMLStreamException {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
//XMLEvent end = eventFactory.createDTD("\n");
//XMLEvent tab = eventFactory.createDTD("\t");
// Create Start node
StartElement sElement = eventFactory.createStartElement("", "", name);
//eventWriter.add(tab);
eventWriter.add(sElement);
// Create Content
Characters characters = eventFactory.createCharacters(value);
eventWriter.add(characters);
// Create End node
EndElement eElement = eventFactory.createEndElement("", "", name);
eventWriter.add(eElement);
//eventWriter.add(end);
}
示例8: write
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Override
public void write(XMLEventWriter writer) throws IOException {
try {
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent event = eventFactory.createStartElement("", "", "footer");
writer.add(event);
event = eventFactory.createStartElement("", "", "writeCount");
writer.add(event);
event = eventFactory.createCharacters(String.valueOf(stepExecution.getWriteCount()));
writer.add(event);
event = eventFactory.createEndElement("", "", "writeCount");
writer.add(event);
event = eventFactory.createEndElement("", "", "footer");
writer.add(event);
} catch (XMLStreamException ignored) {
log.warn("Footer 작업 중 예외가 발생했습니다.", ignored);
}
}
示例9: StAXEventAllocatorBase
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
/** Creates a new instance of XMLEventAllocator */
public StAXEventAllocatorBase() {
if (System.getProperty("javax.xml.stream.XMLEventFactory")==null) {
System.setProperty("javax.xml.stream.XMLEventFactory",
"com.sun.xml.internal.fastinfoset.stax.factory.StAXEventFactory");
}
factory = XMLEventFactory.newInstance();
}
示例10: jaxpFactories
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@DataProvider(name = "jaxpFactories")
public Object[][] jaxpFactories() throws Exception {
return new Object[][] {
{ DocumentBuilderFactory.newInstance(), (Produce)factory -> ((DocumentBuilderFactory)factory).newDocumentBuilder() },
{ SAXParserFactory.newInstance(), (Produce)factory -> ((SAXParserFactory)factory).newSAXParser() },
{ SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI), (Produce)factory -> ((SchemaFactory)factory).newSchema() },
{ TransformerFactory.newInstance(), (Produce)factory -> ((TransformerFactory)factory).newTransformer() },
{ XMLEventFactory.newInstance(), (Produce)factory -> ((XMLEventFactory)factory).createStartDocument() },
{ XMLInputFactory.newInstance(), (Produce)factory -> ((XMLInputFactory)factory).createXMLEventReader(new StringReader("")) },
{ XMLOutputFactory.newInstance(), (Produce)factory -> ((XMLOutputFactory)factory).createXMLEventWriter(new StringWriter()) },
{ XPathFactory.newInstance(), (Produce)factory -> ((XPathFactory)factory).newXPath() },
{ DatatypeFactory.newInstance(), (Produce)factory -> ((DatatypeFactory)factory).newXMLGregorianCalendar() }
};
}
示例11: testEncodingSet
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Test
public void testEncodingSet() {
XMLEventFactory f = XMLEventFactory.newInstance();
try {
StartDocument sd = f.createStartDocument("UTF-8");
System.out.println("Encoding: " + sd.getCharacterEncodingScheme());
System.out.println("Encoding set: " + sd.encodingSet());
Assert.assertTrue(sd.encodingSet(), "encoding is set, should return true.");
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例12: testStandaloneSet
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Test
public void testStandaloneSet() {
XMLEventFactory f = XMLEventFactory.newInstance();
try {
StartDocument sd = f.createStartDocument("UTF-8", "1.0", true);
System.out.println(sd.isStandalone());
System.out.println(sd.standaloneSet());
Assert.assertTrue(sd.standaloneSet(), "standalone is set, should return true.");
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例13: testEventWriterWithStAXResultNStreamWriter
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Test
public void testEventWriterWithStAXResultNStreamWriter() {
String encoding = "";
if (getSystemProperty("file.encoding").equals("UTF-8")) {
encoding = " encoding=\"UTF-8\"";
}
final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"" + encoding + "?><root></root>";
try {
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XMLStreamWriter swriter = ofac.createXMLStreamWriter(buffer);
StAXResult res = new StAXResult(swriter);
XMLEventWriter writer = ofac.createXMLEventWriter(res);
XMLEventFactory efac = XMLEventFactory.newInstance();
writer.add(efac.createStartDocument(null, "1.0"));
writer.add(efac.createStartElement("", "", "root"));
writer.add(efac.createEndElement("", "", "root"));
writer.add(efac.createEndDocument());
writer.close();
Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例14: testEventWriterWithStAXResultNEventWriter
import javax.xml.stream.XMLEventFactory; //导入方法依赖的package包/类
@Test
public void testEventWriterWithStAXResultNEventWriter() {
String encoding = "";
if (getSystemProperty("file.encoding").equals("UTF-8")) {
encoding = " encoding=\"UTF-8\"";
}
final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"" + encoding + "?><root></root>";
try {
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XMLEventWriter writer = ofac.createXMLEventWriter(buffer);
StAXResult res = new StAXResult(writer);
writer = ofac.createXMLEventWriter(res);
XMLEventFactory efac = XMLEventFactory.newInstance();
writer.add(efac.createStartDocument(null, "1.0"));
writer.add(efac.createStartElement("", "", "root"));
writer.add(efac.createEndElement("", "", "root"));
writer.add(efac.createEndDocument());
writer.close();
Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例15: 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);
}