下面列出了org.springframework.util.xml.StaxUtils#createStaxSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test
@Override
@SuppressWarnings("unchecked")
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
streamReader.nextTag(); // skip to flight
Source source = StaxUtils.createStaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test
@Override
@SuppressWarnings("unchecked")
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
streamReader.nextTag(); // skip to flight
Source source = StaxUtils.createStaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalStaxSourceXmlEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(eventReader);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
@Test
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test
@Override
@SuppressWarnings("unchecked")
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
streamReader.nextTag(); // skip to flight
Source source = StaxUtils.createStaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
Source source = StaxUtils.createStaxSource(streamReader);
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
@Test
@Override
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}