當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEventFactory.createStartDocument方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLEventFactory.createStartDocument方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventFactory.createStartDocument方法的具體用法?Java XMLEventFactory.createStartDocument怎麽用?Java XMLEventFactory.createStartDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLEventFactory的用法示例。


在下文中一共展示了XMLEventFactory.createStartDocument方法的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: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable entity : entities) {
		StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
		eventWriter.add(sElement);
		eventWriter.add(end);
		entity.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}

	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:27,代碼來源:EntityRepository.java

示例4: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<Animal> animals) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME));
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable animal : animals) {
		StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.ANIMAL);
		eventWriter.add(sElement);
		eventWriter.add(end);
		animal.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.ANIMAL);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}

	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:27,代碼來源:AnimalRepository.java

示例5: 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

示例6: 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

示例7: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<Animal> animals) throws FileNotFoundException, XMLStreamException {

		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME));
		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		StartDocument startDocument = eventFactory.createStartDocument();
		eventWriter.add(startDocument);
		StartElement configStartElement = eventFactory.createStartElement("", "", "content");
		eventWriter.add(configStartElement);
		eventWriter.add(end);

		for (XML_Parsable animal : animals) {
			StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.ANIMAL);
			eventWriter.add(sElement);
			eventWriter.add(end);

			animal.encodeToXml(eventWriter);

			EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.ANIMAL);
			eventWriter.add(eElement);
			eventWriter.add(end);
		}

		eventWriter.add(eventFactory.createEndElement("", "", "content"));
		eventWriter.add(eventFactory.createEndDocument());
		eventWriter.close();
	}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:29,代碼來源:AnimalRepository.java

示例8: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();

	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));

	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");

	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);

	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable entitity : entities) {
		StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
		eventWriter.add(sElement);
		eventWriter.add(end);

		entitity.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}

	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:32,代碼來源:EntityRepository.java

示例9: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();

	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));

	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");

	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);

	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable entity : entities) {
		StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
		eventWriter.add(sElement);
		eventWriter.add(end);

		entity.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}

	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:32,代碼來源:EntityRepository.java

示例10: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {

		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		// Create XMLEventWriter
		XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));
		// Create a EventFactory
		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		// Create and write Start Tag
		StartDocument startDocument = eventFactory.createStartDocument();
		eventWriter.add(startDocument);
		// Create content open tag
		StartElement configStartElement = eventFactory.createStartElement("", "", "content");
		eventWriter.add(configStartElement);
		eventWriter.add(end);

		for (XML_Parsable entity : entities) {
			StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
			eventWriter.add(sElement);
			eventWriter.add(end);

			entity.encodeToXml(eventWriter);

			EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
			eventWriter.add(eElement);
			eventWriter.add(end);

		}
		eventWriter.add(eventFactory.createEndElement("", "", "content"));
		eventWriter.add(eventFactory.createEndDocument());
		eventWriter.close();
	}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:33,代碼來源:EntityRepository.java

示例11: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
	// Create XMLEventWriter
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME));
	// Create a EventFactory
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	// Create and write Start Tag
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	// Create content open tag
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);
	for (XML_Parsable employee : employees) {
		StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(sElement);
		eventWriter.add(end);
		employee.encodeToXml(eventWriter);
		EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:28,代碼來源:EmployeeRepository.java

示例12: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {

		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));
		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		StartDocument startDocument = eventFactory.createStartDocument();
		eventWriter.add(startDocument);
		StartElement configStartElement = eventFactory.createStartElement("", "", "content");
		eventWriter.add(configStartElement);
		eventWriter.add(end);

		for (XML_Parsable entity : entities) {
			StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
			eventWriter.add(sElement);
			eventWriter.add(end);

			entity.encodeToXml(eventWriter);

			EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
			eventWriter.add(eElement);
			eventWriter.add(end);
		}

		eventWriter.add(eventFactory.createEndElement("", "", "content"));
		eventWriter.add(eventFactory.createEndDocument());
		eventWriter.close();
	}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:29,代碼來源:EntityRepository.java

示例13: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
	// Create XMLEventWriter
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME));
	// Create a EventFactory
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	// Create and write Start Tag
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	// Create content open tag
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);
	for (Employee employee : employees) {
		StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(sElement);
		eventWriter.add(end);
		employee.encodeToXml(eventWriter);
		EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:28,代碼來源:EmployeeRepository.java

示例14: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
	// Create XMLEventWriter
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME));
	// Create an EventFactory
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	// Create and write Start Tag
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	// Create content open tag
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable employee : employees) {
		StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(sElement);
		eventWriter.add(end);

		employee.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE);
		eventWriter.add(eElement);
		eventWriter.add(end);

	}
	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:32,代碼來源:EmployeeRepository.java

示例15: save

import javax.xml.stream.XMLEventFactory; //導入方法依賴的package包/類
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException {
	XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
	// Create XMLEventWriter
	XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename));
	// Create an EventFactory
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	// Create and write Start Tag
	StartDocument startDocument = eventFactory.createStartDocument();
	eventWriter.add(startDocument);
	// Create content open tag
	StartElement configStartElement = eventFactory.createStartElement("", "", "content");
	eventWriter.add(configStartElement);
	eventWriter.add(end);

	for (XML_Parsable entity : entities) {
		StartElement sElement = eventFactory.createStartElement("", "", this.entityTag);
		eventWriter.add(sElement);
		eventWriter.add(end);

		entity.encodeToXml(eventWriter);

		EndElement eElement = eventFactory.createEndElement("", "", this.entityTag);
		eventWriter.add(eElement);
		eventWriter.add(end);

	}
	eventWriter.add(eventFactory.createEndElement("", "", "content"));
	eventWriter.add(eventFactory.createEndDocument());
	eventWriter.close();
}
 
開發者ID:JavaSummer,項目名稱:JavaMainRepo,代碼行數:32,代碼來源:EntityRepository.java


注:本文中的javax.xml.stream.XMLEventFactory.createStartDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。