当前位置: 首页>>代码示例>>Java>>正文


Java XMLEventFactory.newInstance方法代码示例

本文整理汇总了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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:XMLStreamWriterTest.java

示例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\""));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:XMLStreamWriterTest.java

示例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);
}
 
开发者ID:JavaSummer,项目名称:JavaMainRepo,代码行数:17,代码来源:EntityRepository.java

示例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);
	}
 
开发者ID:JavaSummer,项目名称:JavaMainRepo,代码行数:18,代码来源:EntityRepository.java

示例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);
}
 
开发者ID:JavaSummer,项目名称:JavaMainRepo,代码行数:17,代码来源:EmployeeRepository.java

示例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);

}
 
开发者ID:JavaSummer,项目名称:JavaMainRepo,代码行数:21,代码来源:EntityRepository.java

示例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);

}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:22,代码来源:StaxWriter.java

示例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);
	}
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:24,代码来源:ProductFooterStaxCallback.java

示例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();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:StAXEventAllocatorBase.java

示例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() }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:DefaultFactoryWrapperTest.java

示例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());
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Issue53Test.java

示例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());
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Issue53Test.java

示例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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:StreamResultTest.java

示例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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:StreamResultTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:XMLEventLocationTest.java


注:本文中的javax.xml.stream.XMLEventFactory.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。