java - Add comma separated values between tags -
i have 1 list in adding data database. code follows.
list.add(rs.getstring(rsmetadata.getcolumnname())); object.set(list);
now passing object in output file stream. using jaxb , dom parser creating xml
write.marshall(object,outputstream);
where object= object used set values in xml
as per above code getting desired values columns of database. after setting values list tag in xml. getting in separated tags.
my output:
<value>1</value> <value>2</value> <value>3<value> <value>4</value> . . , on
expected output:
<value>1,2,3,4,5</value>
from code mentioned above not getting in comma separated code. please help.
another approach following using dom parser:
for(string s:list){ element n= doc.createelement("value"); n.appendchild(doc.createtextnode((s))); }
through not getting comma separated values
the general approach if want have commaseparated values turn list string , add string (not list) xml. here's 1 way (assuming use java 8):
list<string> list = arrays.aslist("1", "2", "3", "4", "5"); string commaseparated = string.join(",", list); system.out.println(commaseparated); //gives 1,2,3,4,5
in particular case (the dom parser example gave): in loop, create 1 element each value in list; want create 1 entry (no loop):
string commaseparated = string.join(",", list); element n= doc.createelement("value"); n.appendchild(doc.createtextnode(commaseparated));
Comments
Post a Comment