samedi 1 août 2015

handling special char in xml before passing to SQL

I need to pass XML to SQL server for data processing. As XML is returned from API so there is possibility that it could contain restricted char.

Now how to I replace these char before passing XML object to SQL .

Code I am using to get XML from API is :

string apiurl = "http://ift.tt/1ICAb02";
                XDocument xml = XDocument.Parse(new WebClient().DownloadString(apiurl));

                using (var stringWriter = new StringWriter())
                {
                    using (var xmlTextWriter = XmlWriter.Create(stringWriter))
                    {
                        xml.WriteTo(xmlTextWriter);
                    }

                }

Before passing XML object to SQL store procedure I want to replace restricted char like

& - &
< - &lt;
> - &gt;
" - &quot;
' - &#39;

How do I do this in xml.

Aucun commentaire:

Enregistrer un commentaire