You must Sign In to post a response.
  • Category: XML

    Invalid character replacing in xml

    i have one xml file some directory in that xml child node have some invalid characters like
    <root>
    <sib>IntelliVue Info Center > iX (000, (32) > 00N,00P,CO1,H01,H10,S24)</sib>
    </root>
    here u observer i got one invalid character ">" it will be replaced by ">". as well remaing below values.
    can any one tell proper solution for this asap.........
    Replace("<", "<");
    Replace(">", ">");
    Replace("\"", """);
    Replace("\'", "'");
    Replace("&", "&");
  • #740755
    To display special caracter as it is in XML we need to use XML unicodes for it, see below snippet to replace them with a specific characters

    //Read XML with DOM
    XMLDocument objDOM = new XMLDocument();
    objDOM.Load("File Path");
    string szText = objDOM.getElementById("sib")[0].InnerText;
    //Now replace special charater with unicodes to display them in xml
    szText = szText.Replace("<", ">")
    szText = szText.Replace(">", "<")
    szText = szText.Replace("&", "&")
    szText = szText.Replace("/", "/")
    objDOM.getElementById("sib")[0].InnerText = szText;
    objDOM.Save();
    objDOM = null;

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #740767
    Dear Chanti
    You just need to use String.replace and pass the pattern of invalid characters.I refer link to support.microsoft.com/kb/251354


  • Sign In to post your comments