You are given a string that is either valid XML (when it starts with a '<' character) or the name of a file. Your task is to read the XML document.

In order to parse a document from a string, you need to turn it into an input stream, like this:

InputStream in = new ByteArrayInputStream(str.getBytes());

One of the overloaded parse methods of the DocumentBuilder class accepts an InputStream.

Complete the following file:

import; import; import; import; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class XMLReader { public Document read(String what) throws . . . { . . . if (what.startsWith("<")) { . . . } else { FileInputStream in = new FileInputStream(...); . . . } } // This method is used to check your work. public String check(String what) throws Exception { return read(what).getDocumentElement().getNodeName(); } }