1 package com.thoughtworks.xstream.xml.dom;
2
3 import com.thoughtworks.xstream.xml.CannotParseXMLException;
4 import com.thoughtworks.xstream.xml.XMLReader;
5 import com.thoughtworks.xstream.xml.XMLReaderDriver;
6 import org.w3c.dom.Document;
7 import org.xml.sax.SAXException;
8
9 import javax.xml.parsers.DocumentBuilder;
10 import javax.xml.parsers.DocumentBuilderFactory;
11 import javax.xml.parsers.FactoryConfigurationError;
12 import javax.xml.parsers.ParserConfigurationException;
13 import java.io.ByteArrayInputStream;
14 import java.io.IOException;
15
16 public class DomXMLReaderDriver implements XMLReaderDriver {
17
18 public XMLReader createReader(String xml) {
19 try {
20 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
21 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
22 ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
23 Document document = documentBuilder.parse(inputStream);
24 return new DomXMLReader(document);
25 } catch (FactoryConfigurationError e) {
26 throw new CannotParseXMLException(e);
27 } catch (ParserConfigurationException e) {
28 throw new CannotParseXMLException(e);
29 } catch (SAXException e) {
30 throw new CannotParseXMLException(e);
31 } catch (IOException e) {
32 throw new CannotParseXMLException(e);
33 }
34 }
35
36 }
This page was automatically generated by Maven