Thursday, December 06, 2012

XML Special Characters

I always fail to keep track of what you can and cannot type in XML.
So here is a short list:

" replace with " or 
& replace with & or 
' replace with ' or 
<  replace with &lt; or &#003C;
> replace with &gt; or &#003E;

See more at http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Example
<dummy comment="my 'special' char " >
You then convert it to
<dummy comment="my &apos;special&apos; char " >

Here is a code example converting:
    Private Function encodeXMLEntry(ByVal inData As String) As String
        Dim x As String = inData

        ' Replace special characters, start with & for obvious reasons.
        x = x.Replace("&", "&amp;")
        x = x.Replace("""", "&quot;")
        x = x.Replace("'", "&apos;")
        x = x.Replace("<", "&lt;")
        x = x.Replace(">", "&gt;")

        ' return the escaped string
        Return x
    End Function

No comments:

MySQL to MariaDB

 Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...