I have a trouble with a hand-writting XML. The XML is generated by concat string as this :
ReturnXML += "<agentchimique ";
ReturnXML += "id_prod=\"" + Produit.Id + "\" ";
ReturnXML += "nom_com_prod=\"" + Produit.NomComProd + "\" ";
ReturnXML += "nom_four=\"" + Produit.Fournisseur.NomFour + "\" ";
ReturnXML += "PhraseR=\"" + Produit.PhrasesR.Replace( "<br/>", "@" ) + "\" ";
ReturnXML += "PhraseS=\"" + Produit.PhrasesS.Replace( "<br/>", "@" ) + "\" ";
ReturnXML += "numfds_prod=\"" + Produit.NumfdsProd.ToString() + "\" ";
ReturnXML += "transverse_prod=\"" + Produit.TransverseProd.ToString() + "\" ";
This is only a few part of the whole XML and as you can see, all data is in attribute…
But some parameters as Produit.PhrasesR or Produit.PhrasesS can contains illegal character as < > or &.
This XML is stored as text in SQL and executed by SQL server, with the stored procedure sp_xml_preparedocument to be read in a report services.
This XML can be used too as data to generate as a webpage.
So, what is the quickest and easiest solution to resolve this encoding problem, as know I can not rewrite a true compliant XML (I don’t have any time for this), and this XML is used on many place in my project (replace character would be the easiest but it demand to replace back in reports and webpage).
Thanks for your helping.
You can use SecurityElement.Escape
This will replace
<with<,>with>etc.Although you really should use XDocument to build your xml correctly.