Output format of XML empty element in Java -
i wrote code below xml output.
documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); document document = db.newdocument(); element element = document.createelement("test"); text text = document.createtextnode(""); element.appendchild(text); document.appendchild(element); transformerfactory transfactory = transformerfactory.newinstance(); transformer transformer = transfactory.newtransformer(); transformer.setoutputproperty(outputkeys.indent, "yes"); domsource source = new domsource(document); streamresult result = new streamresult(system.out); transformer.transform(source, result);
what got is
<?xml version="1.0" encoding="utf-8" standalone="no"?> <test/>
what want is
<?xml version="1.0" encoding="utf-8" standalone="no"?> <test></test>
how can this?
many thanks.
there no clean way this..
if feel comfortable use duct-tape solutions, let transformer output html instead of xml:
transformer.setoutputproperty(javax.xml.transform.outputkeys.method, "html");
but again, have point out not clean solution, did trick me stuck similar problem
Comments
Post a Comment