help with web services. parse xml string with dom parser

Please support our RSS, Web Services and SOAP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2009
Posts: 19
Reputation: wewehalim is an unknown quantity at this point 
Solved Threads: 0
wewehalim wewehalim is offline Offline
Newbie Poster

help with web services. parse xml string with dom parser

 
0
  #1
May 27th, 2009
Hi, this is my final project. I have generated an xml string, this is my code:


RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. import java.io.StringReader;
  2. import java.io.IOException;
  3. import javax.xml.parsers.DocumentBuilder;
  4. import javax.xml.parsers.DocumentBuilderFactory;
  5.  
  6. import org.w3c.dom.CharacterData;
  7. import org.w3c.dom.Document;
  8. import org.w3c.dom.Element;
  9. import org.w3c.dom.Node;
  10. import org.w3c.dom.NodeList;
  11. import org.xml.sax.InputSource;
  12.  
  13. <%@ page import="javax.xml.parsers.*" %>
  14. <%@ page import="org.w3c.dom.*" %>
  15. <%@ page import="java.io.*" %>
  16. <%@page import="recipe.*" %>
  17.  
  18. <html>
  19. <head>
  20. <title>RECIPE</title>
  21. </head>
  22. <body>
  23.  
  24. <%
  25. // Instantiate the generated Service
  26. Recipe service = new Recipe();
  27.  
  28. // Get the port using port getter method generated in CalculatorService
  29. RecipePortType port= service.getRecipePort();
  30.  
  31. // Invoke the remote method
  32. FilterRequestType req = new FilterRequestType();
  33. FilterResponseType resp = port.filter(req);
  34. String xmlResult = resp.getRecipelist();
  35.  
  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);
  43. %>
  44.  
  45.  
  46. <% .......................................(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..
Last edited by peter_budo; May 27th, 2009 at 12:59 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: vishugs is an unknown quantity at this point 
Solved Threads: 0
vishugs vishugs is offline Offline
Newbie Poster

URGENT:::webservices Return xmlstring as response

 
0
  #2
24 Days Ago
Hi,
i am very new to webservices.My webservice has to return xmlstring as response. like..
<xml version.....><Returncode>G</ReturnCode><folder name = 'salesfolder' value ='100'></folder> I got simple samples which return a string,but not xmlstring how can i proceed.....plz....
I have to develop webservices using JAX-WS ,JBoss Application server,JBossWS-native......
Can anyone plz..help me out with steps.....

Thanx in Advance....
Last edited by peter_budo; 24 Days Ago at 2:47 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: vishugs is an unknown quantity at this point 
Solved Threads: 0
vishugs vishugs is offline Offline
Newbie Poster

Urgent:XML String

 
0
  #3
24 Days Ago
Hi,
thanks for replying i have gone through that thread before posting,but i am not getting it.
Is that thread is a service or client as i am seeing jsp tags and also its not returning..

I have gone through some links and this is what i got.Please correct me ....
1. i wrote a method which takes string as a parameter.
2. In the method, i am generating a xml Document and transforming that DOM to string and returning that string.
Is i am folowing the correct way?.
In some articles i came to know that it should returning a document type,so that will as string i correct format(tags).Is it correct...

please suggest me.....














Originally Posted by wewehalim View Post
Hi, this is my final project. I have generated an xml string, this is my code:


RSS, Web Services and SOAP Syntax (Toggle Plain Text)
  1. import java.io.StringReader;
  2. import java.io.IOException;
  3. import javax.xml.parsers.DocumentBuilder;
  4. import javax.xml.parsers.DocumentBuilderFactory;
  5.  
  6. import org.w3c.dom.CharacterData;
  7. import org.w3c.dom.Document;
  8. import org.w3c.dom.Element;
  9. import org.w3c.dom.Node;
  10. import org.w3c.dom.NodeList;
  11. import org.xml.sax.InputSource;
  12.  
  13. <%@ page import="javax.xml.parsers.*" %>
  14. <%@ page import="org.w3c.dom.*" %>
  15. <%@ page import="java.io.*" %>
  16. <%@page import="recipe.*" %>
  17.  
  18. <html>
  19. <head>
  20. <title>RECIPE</title>
  21. </head>
  22. <body>
  23.  
  24. <%
  25. // Instantiate the generated Service
  26. Recipe service = new Recipe();
  27.  
  28. // Get the port using port getter method generated in CalculatorService
  29. RecipePortType port= service.getRecipePort();
  30.  
  31. // Invoke the remote method
  32. FilterRequestType req = new FilterRequestType();
  33. FilterResponseType resp = port.filter(req);
  34. String xmlResult = resp.getRecipelist();
  35.  
  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);
  43. %>
  44.  
  45.  
  46. <% .......................................(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..
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC