Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758
{"id":834,"date":"2014-06-05T10:39:44","date_gmt":"2014-06-05T13:39:44","guid":{"rendered":"http:\/\/www.feltex.com.br\/felix\/?p=834"},"modified":"2014-08-19T00:39:04","modified_gmt":"2014-08-19T03:39:04","slug":"criando-xml-xstream-java","status":"publish","type":"post","link":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/","title":{"rendered":"Criando XML em Java XStream"},"content":{"rendered":"

Criando XML em Java XStream<\/H1>
\nOl\u00e1 Amigos,<\/p>\n

Trabalhar com XML em Java pode ser uma tarefa bem f\u00e1cil. Isso porque existem v\u00e1rios frameworks que nos auxiliam nessa atividade. Hoje mostraremos como usar o XStream <\/a>. <\/p>\n

\"xml\"<\/p>\n


\n

Cria\u00e7\u00e3o das classes<\/H2><\/p>\n
\r\npackage br.com.feltex.webservice.xstream;\r\n\r\nimport java.util.Date;\r\n\r\npublic class Cliente {\r\n\t\r\n\tprivate String nome;\r\n\t\r\n\tprivate int codigo;\r\n\t\r\n\tprivate String cpf;\r\n\t\r\n\tprivate double salario;\r\n\t\r\n\tprivate Date dataNascimento;\r\n\r\n\tpublic Cliente(int codigo, String nome) {\r\n\t\tthis.codigo = codigo;\r\n\t\tthis.nome = nome;\r\n\t}\r\n\r\n\tpublic int getCodigo() {\r\n\t\treturn codigo;\r\n\t}\r\n\r\n\tpublic String getCpf() {\r\n\t\treturn cpf;\r\n\t}\r\n\r\n\tpublic Date getDataNascimento() {\r\n\t\treturn dataNascimento;\r\n\t}\r\n\r\n\tpublic String getNome() {\r\n\t\treturn nome;\r\n\t}\r\n\r\n\tpublic double getSalario() {\r\n\t\treturn salario;\r\n\t}\r\n\r\n\tpublic void setCodigo(int codigo) {\r\n\t\tthis.codigo = codigo;\r\n\t}\r\n\r\n\tpublic void setCpf(String cpf) {\r\n\t\tthis.cpf = cpf;\r\n\t}\r\n\r\n\tpublic void setDataNascimento(Date dataNascimento) {\r\n\t\tthis.dataNascimento = dataNascimento;\r\n\t}\r\n\r\n\tpublic void setNome(String nome) {\r\n\t\tthis.nome = nome;\r\n\t}\r\n\r\n\tpublic void setSalario(double salario) {\r\n\t\tthis.salario = salario;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Cliente [nome=\" + nome + \", codigo=\" + codigo + \", cpf=\" + cpf\r\n\t\t\t\t+ \", salario=\" + salario + \", dataNascimento=\" + dataNascimento\r\n\t\t\t\t+ \"]\";\r\n\t}\t\r\n}\r\n<\/pre>\n

Em seguida crie a classe XStreamParser que transformar\u00e1 o objeto Cliente em XML e transformar\u00e1 de xml para objeto. <\/p>\n

\r\npackage br.com.feltex.webservice.xstream;\r\n\r\nimport java.io.File;\r\nimport java.io.FileWriter;\r\nimport java.util.Date;\r\n\r\nimport com.thoughtworks.xstream.XStream;\r\nimport com.thoughtworks.xstream.io.xml.DomDriver;\r\n\r\npublic class XStreamParser {\r\n\r\n\tpublic static void main(String arg[]) {\r\n\t\ttry {\r\n\t\t\t\/\/ Cria\u00e7\u00e3o do objeto\r\n\t\t\tCliente cli = new Cliente(1, \"Maria da Silva\");\r\n\t\t\tcli.setDataNascimento(new Date());\r\n\t\t\tcli.setSalario(223.09);\r\n\t\t\tXStream xstream = new XStream(new DomDriver());\r\n\r\n\t\t\txstream.alias(\"cliente\", Cliente.class);\r\n\t\t\tString xml = xstream.toXML(cli);\r\n\r\n\t\t\t\/\/ Sa\u00edda do resultado\r\n\t\t\tSystem.out.println(xml);\r\n\r\n\t\t\tFileWriter fw = new FileWriter(\"meuCliente.xml\");\r\n\t\t\tfw.write(xml);\r\n\t\t\tfw.close();\r\n\r\n\t\t\t\/\/ Retorno de um XML para uma classe\r\n\t\t\tCliente novoCliente = (Cliente) xstream.fromXML(new File(\r\n\t\t\t\t\t\"meuCliente.xml\"));\r\n\t\t\tSystem.out.println(novoCliente);\r\n\r\n\t\t} catch (Exception e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n

Pronto. Agora voc\u00ea j\u00e1 sabe criar XML de forma simples e pr\u00e1tica.<\/p>\n

Conclus\u00e3o:<\/H2>
\n Utilizar o xStream \u00e9 uma \u00f3tima solu\u00e7\u00e3o para manipula\u00e7\u00e3o de XML em Java. Aproveite esta poderosa ferramenta e construa suas exporta\u00e7\u00f5es para XML de forma pr\u00e1tica e simples.
\n H\u00e1 tamb\u00e9m a possibilidade de constru\u00e7\u00e3o de arquivos no formato JSON.<\/p>\n

Links relacionados:<\/H2><\/p>\n

Acesse o site oficial do xStream clique aqui.<\/a><\/p>\n

Gostou do post? Agrade\u00e7a o autor compartilhando nas redes sociais. Clique nos links abaixo:<\/b><\/H2><\/p>\n","protected":false},"excerpt":{"rendered":"

Criando XML em Java XStream Ol\u00e1 Amigos, Trabalhar com XML em Java pode ser uma tarefa bem f\u00e1cil. Isso porque existem v\u00e1rios frameworks que nos auxiliam nessa atividade. Hoje mostraremos como usar o XStream .<\/p>\n","protected":false},"author":1,"featured_media":1293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[1,4,2],"tags":[],"yoast_head":"\nCriando XML em Java XStream<\/title>\n<meta name=\"description\" content=\"Criando XML em Java XStream\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Criando XML em Java XStream\" \/>\n<meta property=\"og:description\" content=\"Criando XML em Java XStream\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Aprenda Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/feltex.br\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-05T13:39:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-08-19T03:39:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1023\" \/>\n\t<meta property=\"og:image:height\" content=\"772\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andr\u00e9 F\u00e9lix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/\",\"name\":\"Aprenda Java\",\"description\":\"Cursos de java, SQL e Engenharia de Software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#primaryimage\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg\",\"contentUrl\":\"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg\",\"width\":1023,\"height\":772,\"caption\":\"xml\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#webpage\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/\",\"name\":\"Criando XML em Java XStream\",\"isPartOf\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#primaryimage\"},\"datePublished\":\"2014-06-05T13:39:44+00:00\",\"dateModified\":\"2014-08-19T03:39:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\"},\"description\":\"Criando XML em Java XStream\",\"breadcrumb\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Criando XML em Java XStream\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\",\"name\":\"Andr\\u00e9 F\\u00e9lix\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#personlogo\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"caption\":\"Andr\\u00e9 F\\u00e9lix\"},\"sameAs\":[\"http:\/\/www.feltex.com.br\"],\"url\":\"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Criando XML em Java XStream","description":"Criando XML em Java XStream","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/","og_locale":"pt_BR","og_type":"article","og_title":"Criando XML em Java XStream","og_description":"Criando XML em Java XStream","og_url":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/","og_site_name":"Aprenda Java","article_publisher":"https:\/\/www.facebook.com\/feltex.br","article_published_time":"2014-06-05T13:39:44+00:00","article_modified_time":"2014-08-19T03:39:04+00:00","og_image":[{"width":1023,"height":772,"url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg","type":"image\/jpeg"}],"twitter_misc":{"Escrito por":"Andr\u00e9 F\u00e9lix","Est. tempo de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.feltex.com.br\/felix\/#website","url":"https:\/\/www.feltex.com.br\/felix\/","name":"Aprenda Java","description":"Cursos de java, SQL e Engenharia de Software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#primaryimage","inLanguage":"pt-BR","url":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg","contentUrl":"https:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/06\/xml.jpg","width":1023,"height":772,"caption":"xml"},{"@type":"WebPage","@id":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#webpage","url":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/","name":"Criando XML em Java XStream","isPartOf":{"@id":"https:\/\/www.feltex.com.br\/felix\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#primaryimage"},"datePublished":"2014-06-05T13:39:44+00:00","dateModified":"2014-08-19T03:39:04+00:00","author":{"@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069"},"description":"Criando XML em Java XStream","breadcrumb":{"@id":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.feltex.com.br\/felix\/criando-xml-xstream-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Criando XML em Java XStream"}]},{"@type":"Person","@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069","name":"Andr\u00e9 F\u00e9lix","image":{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/#personlogo","inLanguage":"pt-BR","url":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","caption":"Andr\u00e9 F\u00e9lix"},"sameAs":["http:\/\/www.feltex.com.br"],"url":"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/"}]}},"_links":{"self":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/834"}],"collection":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/comments?post=834"}],"version-history":[{"count":8,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":1294,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/834\/revisions\/1294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media\/1293"}],"wp:attachment":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media?parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/categories?post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/tags?post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}