{"id":337,"date":"2019-05-12T22:54:01","date_gmt":"2019-05-12T13:54:01","guid":{"rendered":"https:\/\/0x0c.info\/?p=337"},"modified":"2019-05-12T22:54:01","modified_gmt":"2019-05-12T13:54:01","slug":"%e3%80%90java%e3%80%91-xml%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%8b%e3%82%89%e8%a8%ad%e5%ae%9a%e3%82%92%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%80","status":"publish","type":"post","link":"https:\/\/0x0c.info\/?p=337","title":{"rendered":"\u3010Java\u3011 xml\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8a2d\u5b9a\u3092\u8aad\u307f\u8fbc\u3080"},"content":{"rendered":"<p>\t\t\t\t\u307e\u305axml\u30d5\u30a1\u30a4\u30eb(\u3053\u3053\u3067\u306fconfig.xml)\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre><code>        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n        DocumentBuilder builder = factory.newDocumentBuilder();\n        Document document = builder.parse(\"config.xml\");\n        Element root = document.getDocumentElement();\n<\/code><\/pre>\n<hr \/>\n<p>\u5358\u4e00\u306e\u8a2d\u5b9a(String\u3067\u8fd4\u3059)\u7528\u3068\u3001\u8907\u6570\u306e\u8a2d\u5b9a(ArrayList<String>\u3067\u8fd4\u3059)\u7528\u306b\u3001\u95a2\u6570\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<pre><code>    public static String getconfig(Element root, String tag) {\n        NodeList nodeList = root.getElementsByTagName(tag);\n        Node node = nodeList.item(0);\n        String str=node.getTextContent();\n        return str;\n    }\n\n    public static ArrayList&lt;String&gt; getconfigarr(Element root, String tag) {\n        NodeList nodeList = root.getElementsByTagName(tag);\n        ArrayList&lt;String&gt; a = new ArrayList&lt;&gt;();\n        for (int i = 0; i &lt; nodeList.getLength(); i++) {\n            Node node = nodeList.item(i);\n            a.add(node.getTextContent());\n        }\n        return a;\n    }\n<\/code><\/pre>\n<hr \/>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre><code>        String filename=getconfig(root,\"filename\");\n        ArrayList&lt;String&gt; fromAddresses = getconfigarr(root,\"fromaddress\");\n        int pictureWidth=Integer.parseInt(getconfig(root,\"pictureWidth\"));\n        boolean debug=Boolean.parseBoolean(getconfig(root,\"debug\"));\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u307e\u305axml\u30d5\u30a1\u30a4\u30eb(\u3053\u3053\u3067\u306fconfig.xml)\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304a\u304d\u307e\u3059\u3002 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(&#8220;config.xml&#8221;); Element root = document.getDocumentElement(); \u5358\u4e00\u306e\u8a2d\u5b9a(String\u3067\u8fd4\u3059)\u7528\u3068\u3001\u8907\u6570\u306e\u8a2d\u5b9a(ArrayList\u3067\u8fd4\u3059)\u7528\u306b\u3001\u95a2\u6570\u3092\u7528\u610f\u3057\u307e\u3059\u3002 public static String getconfig(Element root, String tag) { NodeList nodeList = root.getElementsByTagName(tag); Node node = nodeList.item(0); String str=node.getTextContent(); return str; } public static ArrayList&lt;String&gt; getconfigarr(Element root, String tag) { NodeList nodeList = root.getElementsByTagName(tag); ArrayList&lt;String&gt; a = new &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/0x0c.info\/?p=337\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u3010Java\u3011 xml\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8a2d\u5b9a\u3092\u8aad\u307f\u8fbc\u3080&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[38,84,213,214],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-xml","tag-213","tag-214"],"_links":{"self":[{"href":"https:\/\/0x0c.info\/index.php?rest_route=\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/0x0c.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/0x0c.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/0x0c.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/0x0c.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":0,"href":"https:\/\/0x0c.info\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"wp:attachment":[{"href":"https:\/\/0x0c.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/0x0c.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/0x0c.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}