DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   RSS, Web Services and SOAP (http://www.daniweb.com/forums/forum151.html)
-   -   help with web services. parse xml string with dom parser (http://www.daniweb.com/forums/thread194174.html)

wewehalim May 27th, 2009 4:52 am
help with web services. parse xml string with dom parser
 
Hi, this is my final project. I have generated an xml string, 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)



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..

vishugs Oct 17th, 2009 2:37 pm
URGENT:::webservices Return xmlstring as response
 
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....

vishugs Oct 17th, 2009 4:12 pm
Urgent:XML String
 
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.....














Quote:

Originally Posted by wewehalim (Post 877090)
Hi, this is my final project. I have generated an xml string, 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)



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..



All times are GMT -4. The time now is 1:30 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC