How to prevent self-closing <tags/> in XML?

Dharel :

I modify XML file using the Transformer class and transform method. It correctly modify my parameters but changed XML style (write XML attributes in different way):

Original:

<a struct="b"></a>
<c></c>

After edit:

<a struct="b"/>
<c/>

I know that I can set properties: transformer.setOutputProperty(OutputKeys.KEY,value), but I did not find proper settings.

Can anyone help the transformer not change the write format?

XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()
Source src = new SAXSource(xr, new InputSource(new 
StringReader(xmlArray[i])));
<<modify xml>>
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();          
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes");
           StringWriter buffer = new StringWriter();
            transformer.transform(src, new StreamResult(buffer));
            xmlArray[i] = buffer.toString();
kjhughes :

Those forms are semantically equivalent. No conforming XML parser will care, and neither should you.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=129194&siteId=1