@Override public Object unmarshal(Source source) throws XmlMappingException { try { XMLEventReader xmlEventReader = StaxTestUtils.getXmlEventReader(source); xmlEventReader.nextEvent(); xmlEventReader.nextEvent(); return xmlEventReader.getElementText(); } catch (Exception e) { throw new RuntimeException(e); } } });
@Override public void marshal(Object graph, Result result) throws XmlMappingException, IOException { super.marshal(graph, result); try { StaxTestUtils.getXmlEventWriter(result).close(); } catch (Exception e) { throw new RuntimeException("Exception while writing to output file", e); } }
@Override public void marshal(Object graph, Result result) throws XmlMappingException, IOException { try { StaxTestUtils.getXmlEventWriter(result).add(XMLEventFactory.newInstance().createComment(graph.toString())); } catch ( Exception e) { throw new RuntimeException("Exception while writing to output file", e); } }
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr = null ; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader( source); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch (Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
@Override public void marshal(Object graph, Result result) throws XmlMappingException, IOException { Assert.isInstanceOf( Result.class, result); try { StaxTestUtils.getXmlEventWriter( result ).add( XMLEventFactory.newInstance().createStartElement(namespacePrefix, namespace, graph.toString())); StaxTestUtils.getXmlEventWriter( result ).add( XMLEventFactory.newInstance().createEndElement(namespacePrefix, namespace, graph.toString())); } catch ( Exception e) { throw new RuntimeException("Exception while writing to output file", e); } }
@Override public Object unmarshal(Source source) throws XmlMappingException, IOException { Attribute attr; try { XMLEventReader eventReader = StaxTestUtils.getXmlEventReader(source ); assertTrue(eventReader.nextEvent().isStartDocument()); StartElement event = eventReader.nextEvent().asStartElement(); attr = (Attribute) event.getAttributes().next(); } catch ( Exception e) { throw new RuntimeException(e); } Foo foo = new Foo(); foo.setValue(Integer.parseInt(attr.getValue())); return foo; }
@Override public void marshal(Object graph, Result result) throws XmlMappingException, IOException { Assert.isInstanceOf(Result.class, result); try { XMLEventFactory factory = XMLEventFactory.newInstance(); XMLEventWriter writer = StaxTestUtils.getXmlEventWriter(result); writer.add(factory.createStartDocument("UTF-8")); writer.add(factory.createStartElement("prefix", "namespace", graph.toString())); writer.add(factory.createEndElement("prefix", "namespace", graph.toString())); writer.add(factory.createEndDocument()); } catch ( Exception e) { throw new RuntimeException("Exception while writing to output file", e); } }
XMLEventReader eventReader = StaxTestUtils.getXmlEventReader(source);