简体   繁体   中英

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)

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.

有一个称为WSDL4J的专用库,该库允许解析WSDL文件。

手动 DOM操作相比, JAXB功能更强大,代码更少。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM