cancel
Showing results for 
Search instead for 
Did you mean: 

WS returning String instead of XML

Former Member
0 Kudos

Hi all,

I'm using a public WS and the service returns me a (very long) string containing XML code.

I'd like to display those data in a WD table: can anyone tell how to retrieve the fields (to form columns) and the data (to fill lines) ?

Thanks in advance !

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Here is the first step code to convert the xml string to a xml document using Dom4j.

Document doc = DocumentHelper.parseText(xmlString);

Element root = doc.getRootElement();

parseNode(root);

Code your parseNode(Element e) method to parse all the nodes of root tag to populate your WD table.

Regards,

Uma

Message was edited by: Uma Maheswari

Answers (2)

Answers (2)

former_member184385
Active Participant
0 Kudos

Hi Francois,

these are the option, for the moment I can think of, to convert a XML string to Java Objects:

1a. First, use the SAP XML Parser's DOM builder and create a DOM as an intermediary step. Then traverse the DOM and populate your WD table

1b. A variant of 1a would be to use and XML library like dom4j or XOM, to create a DOM, which is less brittle to handle, then the original (W3C) DOM

2. First, use a Java/XML binding framework like JAXB, Digester or JiXB to convert your XML string to a Java Object tree. Then traverse the created object and populate your WD table. Digester and JiXB are very flexible, and by chance you may be able to create/populate your WD table already in the first step.

My advise: use Digester or JiXB

Download sites:

- dom4j: http://www.dom4j.org/download.html

- XOM: http://www.xom.nu/

- Digester: http://jakarta.apache.org/site/downloads/downloads_commons-digester.cgi

- JiXB: http://jibx.sourceforge.net/

- JAXB: http://java.sun.com/webservices/jaxb/

Good Luck!

Gregor

Former Member
0 Kudos

Did you consider parsing the string with SAX Parser and then populate your webdynpro context with values being intercepted while parsing with your own handler?

Look at http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/helpers/DefaultHandler.html

you may want to extend the default handler.

Hope this helps.

Kind regards, Vitaliano.