Chris V.
Chris V.

Reputation: 1143

Parsing XML with DOM : Java

I have an XML document that I've received from my server. I need to use this file (which is a WSDL, by the way) to print out a method signature for each of the methods in the WSDL. I've heard that I should be using DOM for this, but I'm not sure how it's used for accomplishing said task. Which parts of DOM should I be using to get the method information? (return type, method name, and parameters)

Upvotes: 0

Views: 770

Answers (3)

user177800
user177800

Reputation:

JAXB is much more powerful and much less code than manual DOM manipulation will be.

Upvotes: 1

G_H
G_H

Reputation: 11999

You don't have to use DOM, it's just one of the many possibilities. DOM is nice if you need random access to any part of the XML, like when using it to store and use structural data over an extended period of time.

Even then, these days you'll find JAXB to be a much more natural fit. It binds XML structure to Java classes, turning XML documents into instances of those classes for easy use in Java code. Since JAXB was created in the context of web service support you'll probably find good support there.

But I think for your purposes, you could even do with just an XSLT transformation. A stylesheet could be written that outputs simple text based on those elements that describe methods. XSLT in Java is simple to use, there's a default implementation in the Sun JRE and it's highly performant. I'd definitely look into XSLT as your first option.

Upvotes: 3

Andreas Veithen
Andreas Veithen

Reputation: 9154

There is a specialized library called WSDL4J that allows to parse WSDL files.

Upvotes: 2

Related Questions