Saturday, 15 March 2014

java - create and write file from XML -



java - create and write file from XML -

i have xml article

<article id="74"> <article_category_id>1</article_category_id > <article_name>......</article_name > <article_extension>pdf</article_extension > <article_byte>[b@6d78f375</article_byte > <article_date>2014-10-11 00:00:00.0</article_date > <article_active>1</article_active> </makale>

i want create file ,and write article_byte can't ,it seems, byte seems string quess don't know how can ? give thanks helping

//edit sorry i'm new stackoverflow.. yes programme i've written.

that's part of code program

try { documentbuilderfactory docfactory = documentbuilderfactory.newinstance(); documentbuilder docbuilder = docfactory.newdocumentbuilder(); // xml kok ismi document doc = docbuilder.newdocument(); element rootelement = doc.createelement("articles"); doc.appendchild(rootelement); (nesne nesne : userlist) { // article element element article_id= doc.createelement("article "); rootelement.appendchild(article_id); //id attr attr = doc.createattribute("id"); attr.setvalue(string.valueof(nesne.getarticleid())); makale_id.setattributenode(attr); //article_category_id element article_category_id= doc.createelement("article_category_id"); article_category_id.appendchild(doc.createtextnode(string.valueof(nesne.getarticle_category_id()))); article_id.appendchild(article_category_id); //[article_name] element article_name= doc.createelement("article_name"); article_name.appendchild(doc.createtextnode(nesne.getarticle_name())); article_id.appendchild(article_name); //[article_extension] element article_extension= doc.createelement("article_extension"); article_extension.appendchild(doc.createtextnode(nesne.getarticle_extension())); article_id.appendchild(article_extension); //[article_byte] element article_byte= doc.createelement("article_byte"); article_byte.appendchild(doc.createtextnode(nesne.getarticle_byte().tostring())); article_id.appendchild(article_byte); //[article_date] element article_date = doc.createelement("article_date"); article_date.appendchild(doc.createtextnode(nesne.getarticle_date())); article_id.appendchild(article_date); //[article_active] element article_active= doc.createelement("article_active"); article_active.appendchild(doc.createtextnode(string.valueof(nesne.getarticleactive()))); article_id.appendchild(article_active); } // write content xml file transformerfactory transformerfactory = transformerfactory.newinstance(); transformer transformer = transformerfactory.newtransformer(); domsource source = new domsource(doc); streamresult result = new streamresult(new file("dosyalar.xml")); // output console testing // streamresult result = new streamresult(system.out); transformer.transform(source, result); system.out.println("file saved!");

your problem appears here:

nesne.getarticle_byte().tostring()

i'm not familiar nesne class, can tell method, getarticle_byte() returns byte array, calling tostring() on homecoming useless info you're seeing, , if needs stored, somehow need store entire array. using loop , storing array string representations of each byte not efficient thing , lead super-large unreadable xml, perhaps store off of xml , pass reference byte array file in xml. or store in database blob. note not much of, , i'm no expert.

java android xml

No comments:

Post a Comment