Unescape XML String - CSharp System.Xml

CSharp examples for System.Xml:XML String

Description

Unescape XML String

Demo Code

/**/* w w  w . j av a2  s .c  o m*/
         * Returns the IANA encoding name that is auto-detected from
         * the bytes specified, with the endian-ness of that encoding where appropriate.
         * (method found in org.apache.xerces.impl.XMLEntityManager, originally published
         * by the Apache Software Foundation under the Apache Software License; now being
         * used in iText under the MPL)
         * @param b4    The first four bytes of the input.
         * @return an IANA-encoding string
         * @since 5.0.6
         */
using System.Text;
using System;

public class Main{
        /**
         * Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the
         * corresponding character values.
         * @param   s   a string representing a character
         * @return  a character value
         */
        public static int Unescape(String s) {
            if ("apos".Equals(s))
                return '\'';
            if ("quot".Equals(s))
                return '"';
            if ("lt".Equals(s))
                return '<';
            if ("gt".Equals(s))
                return '>';
            if ("amp".Equals(s))
                return '&';
            return -1;
        }
}

Related Tutorials