javax.xml.stream.events.StartDocument Java Examples
The following examples show how to use
javax.xml.stream.events.StartDocument.
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: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testBypassElementBlockNestedPrematureEnd() throws XMLStreamException, ParsingException { String xml = "<a><b><c>test</c>" + "<d>aa<d>nestedD</d></d>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "a"); assertStartTag(reader.nextEvent(), "b"); assertStartTag(reader.nextEvent(), "c"); assertCharacters(reader.nextEvent(), is("test")); assertEndTag(reader.nextEvent(), "c"); StaxParserUtil.bypassElementBlock(reader, "d"); expectedException.expect(XMLStreamException.class); reader.nextEvent(); }
Example #2
Source File: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testBypassElementBlock() throws XMLStreamException, ParsingException { String xml = "<a><b><c>test</c>" + "<d>aa</d></b></a>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "a"); assertStartTag(reader.nextEvent(), "b"); assertStartTag(reader.nextEvent(), "c"); assertCharacters(reader.nextEvent(), is("test")); assertEndTag(reader.nextEvent(), "c"); StaxParserUtil.bypassElementBlock(reader, "d"); assertEndTag(reader.nextEvent(), "b"); assertEndTag(reader.nextEvent(), "a"); }
Example #3
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 #4
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 #5
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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(); }
Example #6
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
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(); }
Example #7
Source File: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testBypassElementBlockWrongPairing() throws XMLStreamException, ParsingException { String xml = "<a><b><c>test</c>" + "<d><b>aa</d><d>nestedD</d></d></b></a>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "a"); assertStartTag(reader.nextEvent(), "b"); assertStartTag(reader.nextEvent(), "c"); assertCharacters(reader.nextEvent(), is("test")); assertEndTag(reader.nextEvent(), "c"); expectedException.expect(ParsingException.class); StaxParserUtil.bypassElementBlock(reader, "d"); }
Example #8
Source File: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testBypassElementBlockAnon() throws XMLStreamException, ParsingException { String xml = "<a><b><c>test</c>" + "<d>aa</d></b></a>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "a"); assertStartTag(reader.nextEvent(), "b"); assertStartTag(reader.nextEvent(), "c"); assertCharacters(reader.nextEvent(), is("test")); assertEndTag(reader.nextEvent(), "c"); StaxParserUtil.bypassElementBlock(reader); assertEndTag(reader.nextEvent(), "b"); assertEndTag(reader.nextEvent(), "a"); }
Example #9
Source File: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testBypassElementBlockNested() throws XMLStreamException, ParsingException { String xml = "<a><b><c>test</c>" + "<d>aa<d>nestedD</d></d></b></a>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "a"); assertStartTag(reader.nextEvent(), "b"); assertStartTag(reader.nextEvent(), "c"); assertCharacters(reader.nextEvent(), is("test")); assertEndTag(reader.nextEvent(), "c"); StaxParserUtil.bypassElementBlock(reader, "d"); assertEndTag(reader.nextEvent(), "b"); assertEndTag(reader.nextEvent(), "a"); }
Example #10
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 #11
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) 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 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(); }
Example #12
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 #13
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 #14
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 #15
Source File: XmlFilterReader.java From knox with Apache License 2.0 | 5 votes |
private void processStartDocument( StartDocument event ) throws ParserConfigurationException { String s; document = XmlUtils.createDocument( false ); pushLevel( null, document, document, config ); writer.write( "<?xml" ); s = event.getVersion(); if( s == null ) { s = DEFAULT_XML_VERSION; } writer.write( " version=\""); writer.write( s ); writer.write( "\"" ); s = event.getCharacterEncodingScheme(); if( s != null ) { writer.write( " encoding=\""); writer.write( s ); writer.write( "\"" ); } writer.write( " standalone=\""); writer.write( event.isStandalone() ? "yes" : "no" ); writer.write( "\"" ); writer.write( "?>" ); }
Example #16
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 #17
Source File: StaxWriter.java From maven-framework-project with MIT License | 5 votes |
public void saveConfig() throws Exception { // Create a XMLOutputFactory XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(configFile)); // 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 config open tag StartElement configStartElement = eventFactory.createStartElement("","", "config"); eventWriter.add(configStartElement); //eventWriter.add(end); // Write the different nodes createNode(eventWriter, "mode", "1"); createNode(eventWriter, "unit", "901"); createNode(eventWriter, "current", "100"); createNode(eventWriter, "interactive", "5"); eventWriter.add(eventFactory.createEndElement("", "", "config")); //eventWriter.add(end); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
Example #18
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 #19
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 #20
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) 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 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(); }
Example #21
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 #22
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) 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 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(); }
Example #23
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.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(); }
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.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 #25
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) 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 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(); }
Example #26
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 animal : employees) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(sElement); eventWriter.add(end); animal.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 #27
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 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(); }
Example #28
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) 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 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(); }
Example #29
Source File: StaxParserUtilTest.java From keycloak with Apache License 2.0 | 5 votes |
@Test public void testGetDOMElementSameElements() throws XMLStreamException, ParsingException { String xml = "<root><test><test><a>b</a></test></test></root>"; XMLEventReader reader = StaxParserUtil.getXMLEventReader(IOUtils.toInputStream(xml, Charset.defaultCharset())); assertThat(reader.nextEvent(), instanceOf(StartDocument.class)); assertStartTag(reader.nextEvent(), "root"); Element element = StaxParserUtil.getDOMElement(reader); assertThat(element.getNodeName(), is("test")); assertThat(element.getChildNodes().getLength(), is(1)); assertThat(element.getChildNodes().item(0), instanceOf(Element.class)); Element e = (Element) element.getChildNodes().item(0); assertThat(e.getNodeName(), is("test")); assertThat(e.getChildNodes().getLength(), is(1)); assertThat(e.getChildNodes().item(0), instanceOf(Element.class)); Element e1 = (Element) e.getChildNodes().item(0); assertThat(e1.getNodeName(), is("a")); assertThat(e1.getChildNodes().getLength(), is(1)); assertThat(e1.getChildNodes().item(0), instanceOf(Text.class)); assertThat(((Text) e1.getChildNodes().item(0)).getWholeText(), is("b")); assertEndTag(reader.nextEvent(), "root"); assertThat(reader.nextEvent(), instanceOf(EndDocument.class)); expectedException.expect(NoSuchElementException.class); Assert.fail(String.valueOf(reader.nextEvent())); }
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(); // 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(); }