Forums Register Login

Reading XML data using DOM

+Pie Number of slices to send: Send
Hi,
I am new to XML .Can any one point out to me what wrong with the following code.
-------------------------------------------
<%@ page contentType="text/html"%>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder " %>
<%@ page import="org.w3c.dom.*" %>
<%
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("C:\\xml\\message.xml");
NodeList n1 = doc.getElementsByTagName("messages");

%>

<html>
<body>
<%=n1.item(0).getFirstChild().getNodeValue() %>
</body>
</html>
------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<message>
<messages>Hello XML .. </messages>
</message>
------------------------------------------

When I run the code above , I getting following error:
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:480)
at java.net.URL.<init>(URL.java:376)
at java.net.URL.<init>(URL.java:330)
at com.sun.xml.parser.InputEntity.init(InputEntity.java:140)
at com.sun.xml.parser.Parser.parseInternal(Parser.java:463)
at com.sun.xml.parser.Parser.parse(Parser.java:284)
at com.sun.xml.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java
:95)
+Pie Number of slices to send: Send
If I had to guess (which I do) I'd think that it didn't like "C:\\xml\\message.xml". Check the API and see what it says about the URLs forms it will accept.
BTW, please change your displayed name to follow the JavaRanch naming policy. You can do this here.
Thanks,
+Pie Number of slices to send: Send
I ran this and it worked fine check your path the code is right, you are getting a malformed URL check the path.
Good Luck I am using tomcat 4.0
Ray
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 817 times.
Similar Threads
need help troublshooting java.net.MalformedURLException
Has anyone worked with Mobile Agents? (Servlet AND Mobile Agent)
Unable to view a simple html page in JEditorPane.
Unable to parse xml file with # in the filename
Reading csv file from within servlet problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:33:27.