{"id":255,"date":"2018-03-28T01:33:19","date_gmt":"2018-03-27T16:33:19","guid":{"rendered":"http:\/\/ito-u-oti.com\/?p=255"},"modified":"2018-05-06T12:26:06","modified_gmt":"2018-05-06T03:26:06","slug":"post-255","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=255","title":{"rendered":"xml\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b"},"content":{"rendered":"<h2 id=\"outline__1\">xml\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b<\/h2>\n<p>xml\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u3053\u3093\u3067\u3001\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\u3067\u3059\u3002<br \/>\n\u7528\u9014\u3068\u3057\u3066\u306fSOAP\u901a\u4fe1\u3067xml\u3092\u6e21\u3057\u305f\u3044\u6642\u306a\u3069\u306b\u4f7f\u3048\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h3 id=\"outline__1_1\">hoge.xml<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot; standalone=&quot;yes&quot;?&gt;\r\n &lt;hogehoge&gt;\r\n  &lt;hoge&gt;\r\n   &lt;name&gt;hogepuge&lt;\/name&gt;\r\n   &lt;address&gt;hogepuge&lt;\/address&gt;\r\n  &lt;\/hoge&gt;\r\n&lt;\/hogehoge&gt;\r\n<\/pre>\n<h3 id=\"outline__1_2\">XmlTransfar.java<\/h3>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage xmlTransfar;\r\n\r\nimport java.io.StringWriter;\r\n\r\nimport javax.xml.parsers.DocumentBuilder;\r\nimport javax.xml.parsers.DocumentBuilderFactory;\r\nimport javax.xml.parsers.ParserConfigurationException;\r\nimport javax.xml.transform.OutputKeys;\r\nimport javax.xml.transform.Result;\r\nimport javax.xml.transform.Source;\r\nimport javax.xml.transform.Transformer;\r\nimport javax.xml.transform.TransformerException;\r\nimport javax.xml.transform.TransformerFactory;\r\nimport javax.xml.transform.dom.DOMSource;\r\nimport javax.xml.transform.stream.StreamResult;\r\n\r\nimport org.w3c.dom.Document;\r\nimport org.w3c.dom.Element;\r\nimport org.w3c.dom.Node;\r\nimport org.w3c.dom.NodeList;\r\n\r\npublic class XmlTransfar {\r\n\r\n    public static void main(String&#x5B;] args) throws Exception {\r\n\r\n        StringBuffer sb = new StringBuffer();\r\n        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r\n\r\n        \/\/ \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u59a5\u5f53\u6027\u3092\u691c\u8a3c\u3057\u306a\u3044\r\n        factory.setValidating(false);\r\n        \/\/ xml\u540d\u524d\u7a7a\u9593\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3088\u3046\u306b\u6307\u5b9a\u3059\u308b\r\n        factory.setNamespaceAware(true);\r\n\r\n        DocumentBuilder builder = factory.newDocumentBuilder();\r\n        \/\/ XML\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a\r\n        Document doc = builder.parse(\r\n                &quot;file:C:\/hoge.xml&quot;);\r\n\r\n        Element element = doc.getDocumentElement();\r\n        \/\/ \u89aa\u30ce\u30fc\u30c9\u304b\u3089\u8aad\u307f\u8fbc\u3080\r\n        Node node = element.getParentNode();\r\n\r\n        sb.append(convertToString(node));\r\n\r\n        \/\/ \u8aad\u307f\u8fbc\u307f\u7d50\u679c\r\n        System.out.println(&quot;\u8aad\u307f\u8fbc\u307f\u7d50\u679c&quot;);\r\n        System.out.println(sb);\r\n\r\n    }\r\n\r\n    \/**\r\n     * \u30ce\u30fc\u30c9\u306e\u8981\u7d20\u5024\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3057\u307e\u3059\u3002 \u30ce\u30fc\u30c9\u5185\u306b\u30bf\u30b0\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u305d\u306e\u30bf\u30b0\u306f\u81ea\u52d5\u6574\u5f62\u3055\u308c\u307e\u3059\u3002\r\n     * @param node \u5909\u63db\u5bfe\u8c61\u306e\u6587\u5b57\u5217\r\n     * @return \u5909\u63db\u5f8c\u6587\u5b57\u5217\r\n     * @throws TransformerException XML\u898f\u7d04\u306b\u9055\u53cd\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u4f8b\u5916\r\n     *\/\r\n    public static String convertToString(\r\n            Node node) throws TransformerException {\r\n        \/\/ \u30ce\u30fc\u30c9\u3092XML\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u307e\u3059\r\n        DOMSource source = new DOMSource(node);\r\n        \/\/ \u6587\u5b57\u5217\u751f\u6210\u7528\u30b9\u30c8\u30ea\u30fc\u30e0\r\n        StringWriter swriter = new StringWriter();\r\n        StreamResult result = new StreamResult(swriter);\r\n        \/\/ XML\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3057\u307e\u3059\r\n        transform(source, result);\r\n        return swriter.toString();\r\n    }\r\n\r\n    \/**\r\n     * XML\u5909\u63db\u30a8\u30f3\u30b8\u30f3\u547c\u3073\u51fa\u3057\u3067\u3059\u3002\r\n     * @param source \u5909\u63db\u5bfe\u8c61\u306eXML\r\n     * @param result \u5909\u63db\u5f8c\u6587\u5b57\u5217\r\n     * @throws TransformerException XML\u898f\u7d04\u306b\u9055\u53cd\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u4f8b\u5916\r\n     *\/\r\n    private static void transform(Source source,\r\n            Result result) throws TransformerException {\r\n        \/\/ \u5909\u63db\u30a8\u30f3\u30b8\u30f3\u3092\u53d6\u5f97\u3057\u307e\u3059\r\n        Transformer transformer = TransformerFactory.newInstance()\r\n                .newTransformer();\r\n        \/\/ XML\u5909\u63db\u306e\u30eb\u30fc\u30eb\u3092\u8a2d\u5b9a\u3057\u307e\u3059\r\n        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, &quot;yes&quot;);\r\n        \/\/ \u5909\u63db\r\n        transformer.transform(source, result);\r\n    }\r\n}\r\n<\/pre>\n<h3 id=\"outline__1_3\">\u7d50\u679c<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u8aad\u307f\u8fbc\u307f\u7d50\u679c\r\n&lt;hogehoge&gt;\r\n  &lt;hoge&gt;\r\n   &lt;name&gt;hogepuge&lt;\/name&gt;\r\n   &lt;address&gt;hogepuge&lt;\/address&gt;\r\n  &lt;\/hoge&gt;\r\n&lt;\/hogehoge&gt;\r\n<\/pre>\n<p><a href=\"http:\/\/www.atmarkit.co.jp\/bbs\/phpBB\/viewtopic.php?topic=40302&#038;forum=12\">\u53c2\u8003\u306b\u306a\u3063\u305f\u3068\u3053\u308d<\/a><br \/>\n\uff08xml\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u3068\u3053\u308d\u306f\u305d\u306e\u307e\u307e\u4f7f\u308f\u305b\u3066\u3082\u3089\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><span class=\"markerYellow\">github\u306b\u30bd\u30fc\u30b9\u3092\u3042\u3052\u3066\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/github.com\/itouoti12\/xmlTransfar\">xmlTransfar<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>xml\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3092\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b xml\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u3053\u3093\u3067\u3001\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\u3067\u3059\u3002 \u7528\u9014 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[96,95],"class_list":["post-255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programing","tag-java","tag-xml"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=255"}],"version-history":[{"count":3,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/255\/revisions\/471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}