Search code examples
htmlasp.netxmldecodeencode

Which is the proper way to save XML value node that contains &#38 into the database?


Today someone has sent an XML to my asp.net 4.8 backend app, like this one:

<person>
   <name>example1 &amp;#38 example2</name>
</person>

The server app reads the node value and saves it in an sql db column dbo.Person.Name without any decoding. first dubt: is it bad ? how should be stored ? Should be decoded first.

Anyway assuming the value will be saved as is, soon or later the client side part of the application will request data from the server and this string will be sent to the client and shown correctly, since it is an html encoded string.

The issue I am dealing with is a Validation Exception thrown when the client gives back this data in a post request to the server.

The easy why should be to replace/escape the "&#38" contained in the post's body.

Is it the best way to deal with ? How data should be transfer beetween server and client ?


Solution

  • "Today someone has sent an XML"

    Get back to them and ask them why they're sending such dirty data and tell them you're not prepared to put such grot in your database.

    It looks on the face of it as if &amp;#38 is a completely botched attempt to escape an ampersand.