John Davidson

php xml dom need whitespace before closing tag ` />`

0 comments
Message:


Want to get output like this <TaksPusgads xsi:nil="true" />


Used such code


 $dom = new DOMDocument();

$dom->appendChild( $dom->createElement("TaksPusgads") )
->appendChild( $dom->createAttribute("xsi:nil") )
->appendChild( $dom->createTextNode('true'));//

$xml = $dom->saveXML();
echo $xml;

Example is here https://sandbox.onlinephpfunctions.com/code/97b175a6722bd6968c8ff715e97479925b58ea6b


But i get <TaksPusgads xsi:nil="true"/>


Instead of "true"/> need "true" /> (whitespace before />).


What code i need to add or ammend?



My Answer:
No, in XML, whitespace before the closing tag `/>` is not required. The XML parser will ignore any whitespace before the closing tag. However, it is recommended to maintain consistent formatting for readability and maintainability of the XML document.

Rate this post

5 of 5 based on 1155 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us