{"id":2128,"date":"2012-06-08T14:41:21","date_gmt":"2012-06-08T12:41:21","guid":{"rendered":"http:\/\/blog.unelink.es\/?p=2128"},"modified":"2012-06-08T14:41:21","modified_gmt":"2012-06-08T12:41:21","slug":"pasar-de-org-w3c-dom-node-a-string","status":"publish","type":"post","link":"https:\/\/hosting.airetech.es\/blog\/wiki\/pasar-de-org-w3c-dom-node-a-string\/","title":{"rendered":"Pasar de org.w3c.dom.Node a String"},"content":{"rendered":"<p>Para realizar dicha\u00a0conversi\u00f3n\u00a0debemos hacer uso de<\/p>\n<pre>DOMSource<\/pre>\n<p>que, a su vez, es usado por<\/p>\n<pre>TransformerFactory<\/pre>\n<p>para completar la\u00a0conversi\u00f3n.<\/p>\n<p>A\u00a0continuaci\u00f3n\u00a0exponemos el\u00a0c\u00f3digo\u00a0que realiza dicha conversi\u00f3n:<\/p>\n<pre>\r\npublic static String toXML(Node nodo)\r\n{\r\n&nbsp;&nbsp;&nbsp;&nbsp;String result = null;\r\n<br \/>\r\n&nbsp;&nbsp;&nbsp;&nbsp;try\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Source source = new DOMSource(nodo);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringWriter stringWriter = new StringWriter();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result result = new StreamResult(stringWriter);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TransformerFactory factory = TransformerFactory.newInstance();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transformer transformer = factory.newTransformer();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transformer.transform(source, result);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = stringWriter.getBuffer().toString();\r\n&nbsp;&nbsp;&nbsp;&nbsp;} catch (Exception e)\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = null;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n<br \/>\r\n&nbsp;&nbsp;&nbsp;&nbsp;return result;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Para realizar dicha\u00a0conversi\u00f3n\u00a0debemos hacer uso de DOMSource que, a su vez, es usado por TransformerFactory para completar la\u00a0conversi\u00f3n. A\u00a0continuaci\u00f3n\u00a0exponemos el\u00a0c\u00f3digo\u00a0que realiza dicha conversi\u00f3n: public static String toXML(Node nodo) { &nbsp;&nbsp;&nbsp;&nbsp;String result = null; &nbsp;&nbsp;&nbsp;&nbsp;try &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Source source = new DOMSource(nodo); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringWriter stringWriter = new StringWriter(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result result = new StreamResult(stringWriter); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TransformerFactory factory = TransformerFactory.newInstance(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transformer transformer = factory.newTransformer(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transformer.transform(source, result);&nbsp;<a href=\"https:\/\/hosting.airetech.es\/blog\/wiki\/pasar-de-org-w3c-dom-node-a-string\/\" class=\"read-more\">Seguir leyendo<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[123,6],"tags":[124,126,127],"class_list":["post-2128","post","type-post","status-publish","format-standard","hentry","category-java","category-wiki","tag-java-2","tag-node","tag-string","cat-123-id","cat-6-id"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/comments?post=2128"}],"version-history":[{"count":12,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2128\/revisions"}],"predecessor-version":[{"id":2156,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/posts\/2128\/revisions\/2156"}],"wp:attachment":[{"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/media?parent=2128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/categories?post=2128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hosting.airetech.es\/blog\/wp-json\/wp\/v2\/tags?post=2128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}