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


Java StartDocument类代码示例

本文整理汇总了Java中javax.xml.stream.events.StartDocument的典型用法代码示例。如果您正苦于以下问题:Java StartDocument类的具体用法?Java StartDocument怎么用?Java StartDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StartDocument类属于javax.xml.stream.events包,在下文中一共展示了StartDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import javax.xml.stream.events.StartDocument; //导入依赖的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

示例2: save

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public void save(ArrayList<Employee> employees) 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 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,代码行数:26,代码来源:EmployeeRepository.java

示例3: save

import javax.xml.stream.events.StartDocument; //导入依赖的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: createDocument

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
/**
 * Create a document from the specified reader.
 * @param reader The XMLEvent reader.
 * @return The Document.
 * @throws ParserConfigurationException For errors creating the document.
 * @throws XMLStreamException For errors reading the event reader.
 */
public static Document createDocument(final XMLEventReader reader)
    throws ParserConfigurationException, XMLStreamException {
    final Document doc = getNewDocument();
    final XMLEventWriter writer = EVENT_WRITER_CREATOR.createXMLEventWriter(doc);
    final XMLEvent event = reader.peek();
    int type = event.getEventType();
    boolean omitDoc = false;
    if (type == XMLStreamConstants.START_DOCUMENT) {
        StartDocument startDocument = (StartDocument) event;
        if (startDocument.getVersion() == null) {
            omitDoc = true;
        }
    }
    XMLHelper.copyXMLEventStream(reader, writer, omitDoc);
    return doc;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:XMLHelper.java

示例5: testEncodingSet

import javax.xml.stream.events.StartDocument; //导入依赖的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.events.StartDocument; //导入依赖的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: getVersion

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
@Override
public String getVersion() {
	if (this.event.isStartDocument()) {
		return ((StartDocument) this.event).getVersion();
	}
	else {
		return null;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:XMLEventStreamReader.java

示例8: isStandalone

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
@Override
public boolean isStandalone() {
	if (this.event.isStartDocument()) {
		return ((StartDocument) event).isStandalone();
	}
	else {
		throw new IllegalStateException();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:XMLEventStreamReader.java

示例9: standaloneSet

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
@Override
public boolean standaloneSet() {
	if (this.event.isStartDocument()) {
		return ((StartDocument) this.event).standaloneSet();
	}
	else {
		throw new IllegalStateException();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:XMLEventStreamReader.java

示例10: createStartDocument

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public StartDocument createStartDocument(String encoding,
                                         String version,
                                         boolean standalone)
{
  return new StartDocumentImpl(location, null, encoding, version,
                               standalone, true, true);
}
 
开发者ID:vilie,项目名称:javify,代码行数:8,代码来源:XMLEventFactoryImpl.java

示例11: isStandalone

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public boolean isStandalone() {
	if (event.isStartDocument()) {
		return ((StartDocument) event).isStandalone();
	}
	else {
		throw new IllegalStateException();
	}
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:9,代码来源:XMLEventStreamReader.java

示例12: getVersion

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public String getVersion() {
	if (event.isStartDocument()) {
		return ((StartDocument) event).getVersion();
	}
	else {
		return null;
	}
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:9,代码来源:XMLEventStreamReader.java

示例13: standaloneSet

import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public boolean standaloneSet() {
	if (event.isStartDocument()) {
		return ((StartDocument) event).standaloneSet();
	}
	else {
		throw new IllegalStateException();
	}
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:9,代码来源:XMLEventStreamReader.java

示例14: save

import javax.xml.stream.events.StartDocument; //导入依赖的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");
	// 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,代码行数:30,代码来源:EntityRepository.java

示例15: save

import javax.xml.stream.events.StartDocument; //导入依赖的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


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