wewehalim 0 Junior Poster in Training

Hi, this is my final project. I have generated an xml string, and i want to parse it with dom parser, but i have error here..
this is my code:


import java.io.StringReader;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

<%@ page import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="java.io.*" %>
<%@page import="recipe.*" %>

<html>
<head>
<title>RECIPE</title>
</head>
<body>

<%
// Instantiate the generated Service
Recipe service = new Recipe();

// Get the port using port getter method generated in CalculatorService
RecipePortType port= service.getRecipePort();

// Invoke the remote method
FilterRequestType req = new FilterRequestType();
FilterResponseType resp = port.filter(req);
String xmlResult = resp.getRecipelist();

// Create an instance of the DOM parser and parse the document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xmlResult)));

// Begin traversing the document
traverseTree(doc, out);
%>


<% .......................................(the rest of the code)

import java.io.StringReader; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.CharacterData; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; <%@ page import="javax.xml.parsers.*" %> <%@ page import="org.w3c.dom.*" %> <%@ page import="java.io.*" %> <%@page import="recipe.*" %> <html> <head> <title>RECIPE</title> </head> <body> <% // Instantiate the generated Service Recipe service = new Recipe(); // Get the port using port getter method generated in CalculatorService RecipePortType port= service.getRecipePort(); // Invoke the remote method FilterRequestType req = new FilterRequestType(); FilterResponseType resp = port.filter(req); String xmlResult = resp.getRecipelist(); // Create an instance of the DOM parser and parse the document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xmlResult))); // Begin traversing the document traverseTree(doc, out); %> <% .......................................(the rest of the code)

whenever i run it in my browser, there will be error like this:

An error occurred at line: 39 in the jsp file: /assignment2/domrecipe.jsp
InputSource cannot be resolved to a type
36: // Create an instance of the DOM parser and parse the document
37: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
38: DocumentBuilder db = dbf.newDocumentBuilder();
39: Document doc = db.parse(new InputSource(new StringReader(xmlResult)));
40:
41: // Begin traversing the document
42: traverseTree(doc, out);

and this:

root cause

java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8"?>
(and then the xml string)


so, basically, the xml string has been read, but there are errors in it... can someone help me..
thanks..