{"id":1654,"date":"2010-04-09T13:10:13","date_gmt":"2010-04-09T05:10:13","guid":{"rendered":"\/?p=1654"},"modified":"2010-04-09T13:10:13","modified_gmt":"2010-04-09T05:10:13","slug":"1654","status":"publish","type":"post","link":"https:\/\/www.justzz.com\/spec\/1654.html","title":{"rendered":"Java Document\u89e3\u6790XML"},"content":{"rendered":"<p><code>document\u89e3\u6790xml\u793a\u4f8b\uff1a<\/code><\/p>\n<p>----------------------------------------------------------<br \/>\nconfig.xml<br \/>\n&lt;?xml version=\"1.0\" encoding=\"GBK\"?&gt;<br \/>\n&lt;param&gt;<br \/>\n&lt;add name=\"pageSize\" value=\"15\"&gt;page&lt;\/add&gt;<br \/>\n&lt;add name=\"webSite\" value=\"Rouselife\"&gt;Test&lt;\/add&gt;<br \/>\n&lt;\/param&gt;<\/p>\n<p>----------------------------------------------------------<br \/>\nClass\u6587\u4ef6\uff1a<br \/>\nimport org.dom4j.Document;<br \/>\nimport org.dom4j.Element;<br \/>\nimport org.dom4j.io.SAXReader;<br \/>\npublic class Util {<br \/>\npublic static String getXmlValue(String path, String param){<br \/>\nSAXReader saxReader = null;<br \/>\nDocument doc = null;<br \/>\ntry {<br \/>\nFile f = new File(path);<br \/>\nsaxReader = new SAXReader();<br \/>\ndoc = saxReader.read(f);<br \/>\nList&lt;Element&gt; list = doc.selectNodes(\"\/\/param\/\/add\");<br \/>\nfor (Element add: list) {<br \/>\nSystem.out.println(add.attribute(\"name\").getStringValue());<br \/>\nSystem.out.println(add.attribute(\"value\").getStringValue());<br \/>\nSystem.out.println(add.getText());<br \/>\n}<br \/>\n} catch (Exception e) {<br \/>\n}<br \/>\nreturn null;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>document\u89e3\u6790xml\u793a\u4f8b\uff1a ---------------------------------------------------------- config.xml &lt;?xml version=\"1.0\" encoding=\"GBK\"?&hellip;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1654","post","type-post","status-publish","format-standard","hentry","category-t"],"_links":{"self":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/comments?post=1654"}],"version-history":[{"count":0,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1654\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media?parent=1654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/categories?post=1654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/tags?post=1654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}