Question

I am using JAXB to unmarshal an XML document. While parsing the XML it is throwing a MalformedURLException wrapped with XMLStreamException. What I understand is while creating the XMLStreamReader object itself it is throwing the exception. Any suggestions please?

The code snippet I am using:

    XMLInputFactory xif = XMLInputFactory.newFactory();      
    XMLResolver resolver = new XMLResolver(); //to capture systemID, base URI etc.
    xif.setXMLResolver(resolver);

    //Throws MalformedURLException  while processing the below line
    XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(fileToProcess));

    JAXBContext jaxbContext = JAXBContext.newInstance(MyPackage.MyClassName.class);

Here is the exception trace:

     class javax.xml.stream.XMLStreamException
     javax.xml.stream.XMLStreamException: java.net.MalformedURLException: no protocol:       [XML_FILEPATH/XML_FILE_NAME]

fileToProcess is a string that contains absolute path, like /home/project/input/myproject.xml

Run time JDK is 1.7. Any signature/protocol I am missing?

Thanks, Bhaskar

Was it helpful?

Solution

Try this:

XMLStreamReader streamReader = factory.createXMLStreamReader(
new FileReader("data\\test.xml"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top