本篇文章为大家展示了怎么实现java DOMParser 解析xml,代码简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了达坂城免费建站欢迎大家使用!
import java.io.*; import java.net.*; import org.w3c.dom.*; import org.w3c.dom.Node.*; import oracle.xml.parser.v2.*; /** * ----------------------------------------------------------------------------- * Demonstrate how to use DOM. * * @version 1.0 * @author Jeffrey M. Hunter (jhunter@idevelopment.info) * @author http://www.idevelopment.info * ----------------------------------------------------------------------------- */ public class DOMExample { /* * +---------------------------------------------+ * | METHOD: main | * +---------------------------------------------+ */ static public void main(String[] argv) { try { if (argv.length != 1) { // must pass in the name of the XML file System.err.println("Usage: java DOMExample filename"); System.exit(1); } // Get an instance of the parser DOMParser parser = new DOMParser(); // Generate a URL from the filename URL url = createURL(argv[0]); // Set various parser options; validation on, // warnings shown, error stream set to stderr. parser.setErrorStream(System.err); parser.setValidationMode(true); parser.showWarnings(true); // parse the document parser.parse(url); // Obtain the document XMLDocument doc = parser.getDocument(); // print document elements System.out.print("The elements are: "); printElements(doc); // print document elements attributes System.out.println("The attributes of each element are: "); printElementAttributes(doc); } catch (Exception e) { System.out.println(e.toString()); } } /* * +---------------------------------------------+ * | METHOD: printElements | * +---------------------------------------------+ */ static void printElements(Document doc) { NodeList nodelist = doc.getElementsByTagName("*"); Node node; for (int i=0; i上述内容就是怎么实现java DOMParser 解析xml,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
当前标题:怎么实现javaDOMParser解析xml
文章源于:http://cdxtjz.cn/article/pcjdos.html