javax.xml.stream.XMLEventFactory Java Examples
The following examples show how to use
javax.xml.stream.XMLEventFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaxXMLWriter.java From journaldev with MIT License | 6 votes |
private static void createNode(XMLEventWriter eventWriter, String element, String value) throws XMLStreamException { XMLEventFactory xmlEventFactory = XMLEventFactory.newInstance(); XMLEvent end = xmlEventFactory.createDTD("\n"); XMLEvent tab = xmlEventFactory.createDTD("\t"); //Create Start node StartElement sElement = xmlEventFactory.createStartElement("", "", element); eventWriter.add(tab); eventWriter.add(sElement); //Create Content Characters characters = xmlEventFactory.createCharacters(value); eventWriter.add(characters); // Create End node EndElement eElement = xmlEventFactory.createEndElement("", "", element); eventWriter.add(eElement); eventWriter.add(end); }
Example #2
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
/** * * @param eventWriter * . * @param name * The name. * @param value * The value. * @throws XMLStreamException * . */ public static void createNode(final XMLEventWriter eventWriter, final String name, final 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); }
Example #3
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #5
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #6
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #7
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #8
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #9
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #10
Source File: ArtifactsXmlAbsoluteUrlRemover.java From nexus-repository-p2 with Eclipse Public License 1.0 | 6 votes |
private Iterator updateSizeAttribute( final Iterator<Attribute> attributes, final int size, final XMLEventFactory eventFactory) { List<Attribute> processedAttributes = new ArrayList<>(); while (attributes.hasNext()) { Attribute attribute = attributes.next(); if (attribute.getName().getLocalPart().equals("size")) { Attribute sizeAttribute = eventFactory.createAttribute(attribute.getName(), Integer.toString(size)); if (sizeAttribute != null) { processedAttributes.add(sizeAttribute); } } else { processedAttributes.add(attribute); } } return processedAttributes.iterator(); }
Example #11
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #12
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #13
Source File: XMLStreamWriterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * @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()); }
Example #14
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #15
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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(); }
Example #16
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #17
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #18
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #19
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #20
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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); }
Example #21
Source File: BatchJobHelperUtility.java From googleads-java-lib with Apache License 2.0 | 5 votes |
@Inject BatchJobHelperUtility( Supplier<Transformer> transformerSupplier, XMLInputFactory xmlInputFactory, XMLOutputFactory xmlOutputFactory, XMLEventFactory xmlEventFactory) { this.transformerSupplier = transformerSupplier; this.xmlInputFactory = xmlInputFactory; this.xmlOutputFactory = xmlOutputFactory; this.xmlEventFactory = xmlEventFactory; }
Example #22
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }
Example #23
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }
Example #24
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }
Example #25
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }
Example #26
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }
Example #27
Source File: ArtifactsXmlAbsoluteUrlRemover.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
private void streamXmlToWriterAndRemoveAbsoluteUrls( final XMLEventReader reader, final XMLEventWriter writer) throws XMLStreamException { final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent previous = null; // We need to buffer events so that we can also update properties size when removing the mirrorsUrl property List<XMLEvent> buffer = new ArrayList<>(); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); // If xml tag is "properties" then start buffering. If started buffering then keep buffering until the buffer // is cleared if (!buffer.isEmpty() || isStartTagWithName(event, "properties")) { //Exclude the mirrorsURL property if (!(isMirrorsUrlProperty(event) || isMirrorsUrlProperty(previous))) { buffer.add(event); } } if (buffer.isEmpty()) { writer.add(event); } // When reached end of <properties> section, update count and flush buffer to writer. if (isEndTagWithName(event, "properties")) { for (XMLEvent xmlEvent : buffer) { if (isStartTagWithName(xmlEvent, "properties")) { xmlEvent = updateSize(xmlEvent.asStartElement(), countPropertyTags(buffer), eventFactory); } writer.add(xmlEvent); } buffer.clear(); } previous = event; } }
Example #28
Source File: ArtifactsXmlAbsoluteUrlRemover.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
private XMLEvent updateSize( final StartElement tag, final int size, final XMLEventFactory eventFactory) { Iterator updatedAttributes = updateSizeAttribute(tag.getAttributes(), size, eventFactory); return eventFactory.createStartElement(tag.getName().getPrefix(), tag.getName().getNamespaceURI(), tag.getName().getLocalPart(), updatedAttributes, null); }
Example #29
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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 animal : entities) { StartElement sElement = eventFactory.createStartElement("", "", this.entityTag); eventWriter.add(sElement); eventWriter.add(end); animal.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(); }
Example #30
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
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(); }