Search code examples
javaxmlxhtmlsaxparsermalformedurlexception

Error while trying to use Sax Parser on xhtml file


I'm trying to parse an xhml file using SAXParser in Java, but gets an exception:

"java.net.MalformedURLException: unknown protocol: g"

The line made that exception was:

SAXBuilder.build(Destination)

While Destination is the full path to the xhml file. The beginning of the xhml file is as followed:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="../article.css" type="text/css"?>
<div id="article" xmlns="http://www.w3.org/1999/xhtml">

While div is the root element.

I tried to look for documentation over the web about protocol g or MalformedURLException, i tried to play with the namespaces as well, but couldn't get this work.

Does anyone have any idea what can i do to make this work?

Thanks


Solution

  • (Based on discussion in the comments) SAXBuilder is treating "Destination" as a URL and not a local file. Call "build" with a File object instead.