Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAXParser Exception : java.net.MalformedURLException: no protocol:

Status
Not open for further replies.

beefeater267

Programmer
Apr 6, 2005
79
Hi,

I'm kind of new to Java and I'm creating a servlet that does the following: it just needs to parse an XML string.

So, I have the following code:

SAXParserFactory parserFactory = SAXParserFactory.newInstance();

parserFactory.setValidating(false);
parserFactory.setNamespaceAware(false);

SAXParser parser = parserFactory.newSAXParser();

//derived from DefaultHandler
SSMHandler handler = new SSMHandler();

XMLStatus = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Command xmlns=\"
parser.parse(XMLStatus, handler);

So, the code throws an exception on the parse method:

I get :
java.net.MalformedURLException: no protocol:

Can anyone help me out with what is going on here?

Greatly appreciated.
 
Why bother adding an anonymous namespace if you are not using it ?
If you are not validating, nor setting the parser as NS aware, I would just use :

XMLStatus = "<Command><a><b><c>config</c><d><e>port</e></d></b></a></Command>";

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Wrong... actually the string parameter is meant to be a URL to a XML file... (not raw xml)
 
So why does your example of the 'XMLStatus' string have a XML content, and not just a URL then ?

Try to post correct data in the future eh ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Plus ... your comment of 'Wrong' (while being slightly rude IMO) is actually valid - why use namespaces in the XML if your parser is not namespace aware ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sedj,

I thought that the argument took raw XML as a string. I did further research and found out that it must be a URL to a file.

PS..... if I had correct data in my post, I wouldn't be here asking for help ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top