本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例11: isStandalone
import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public boolean isStandalone() {
if (event.isStartDocument()) {
return ((StartDocument) event).isStandalone();
}
else {
throw new IllegalStateException();
}
}
示例12: getVersion
import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public String getVersion() {
if (event.isStartDocument()) {
return ((StartDocument) event).getVersion();
}
else {
return null;
}
}
示例13: standaloneSet
import javax.xml.stream.events.StartDocument; //导入依赖的package包/类
public boolean standaloneSet() {
if (event.isStartDocument()) {
return ((StartDocument) event).standaloneSet();
}
else {
throw new IllegalStateException();
}
}
示例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();
}
示例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();
}