wood burning stoves
The moose likes XML and Related Technologies and the fly likes Unable to parse XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Unable to parse XML" Watch "Unable to parse XML" New topic

Unable to parse XML

Hemant Khurana

Joined: Jan 11, 2007
Posts: 27
Hi All

I have a XML which starts like this...

<?xml version="1.0"?>
<!DOCTYPE SOURCE SYSTEM "classpath://com/store/find/tour/dtd/paramsourcescript.dtd">
<SOURCE name="store">
<GROUP hidden="N" name="PHONE">

I am using the the following Java code to parse this XML

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
System.out.println(">--- Parsing test.xml ----<");
try {

//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();

//parse using builder to get DOM representation of the XML file
Document dom = db.parse("test.xml");

//get the root element
Element docEle = dom.getDocumentElement();

I am getting the following exception when I parse this XML

java.net.MalformedURLException: unknown protocol: classpath
at java.net.URL.<init>(URL.java:574)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:968)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:184)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:146)

If I remove the DOCTYPE element in my XML them I am able to parse the XML. Please help how can I resolve this to parse the XML with the DOCTYPE element in XML

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
"classpath" is not a standard URI scheme. You may have to add an entity resolver that knows how to deal with it.
I agree. Here's the link: http://aspose.com/file-tools
subject: Unable to parse XML
It's not a secret anymore!