Search code examples
phpmysqlxmlwriterxml-nil

XMLWriter () Replace blank strings


I am using XMLWriter to create an XML output of my MySQL Database, and I would like to know how I could prevent this happening <hello></hello> by doing this <hello>nil</hello>

So basically replace "" with "nil".


Solution

  • <hello></hello> is proper for indicating an empty node in XML; the other way is <hello />. Replacing with nil means it's no longer an empty node; it's a node with the text content nil.

    If you do that replacement, you're changing the meaning of the data in the XML. This is a terrible idea.