XML string to Java Object...

B

Bogus Exception

It would seem simple, but it is proving difficult to find an example
that takes XML from a web service and creates java objects from it.
Given the output of the web service:

<Commands xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>The Name</Name>
<Command>The Command</Command>
</Commands>

I just need to make objects of type:

public class Commands {
static final long serialVersionUID = 1;
public String Name;
public String Command;
}

TIA!
 
V

voorth

It would seem simple, but it is proving difficult to find an example
that takes XML from a web service and creates java objects from it.
Given the output of the web service:

<Commands xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>The Name</Name>
<Command>The Command</Command>
</Commands>

I just need to make objects of type:

public class Commands {
static final long serialVersionUID = 1;
public String Name;
public String Command;

}

TIA!

If you don't mind using a 3rd party lib, I would recommend Castor:
http://castor.codehaus.org/

It gives you the possibility of generating classes from XML schema's,
or ,if you already have your classes, to use a mapping. I've found
the maintainers very helpful if you have problems getting started.

Henk
 
L

Lew

If you use Apache Axis, there is the WSDL2Java tool. The project's
documentation is the place to look for examples.

-- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top