• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to parse XML  RSS feed

Hemant Khurana
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"classpath" is not a standard URI scheme. You may have to add an entity resolver that knows how to deal with it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!