Static Public Member Functions | Private Member Functions

XMLStorage::XMLHelper Class Reference

XMLHelpder converts XML string literals. More...

List of all members.

Static Public Member Functions

static string encodeXMLString (string s)
 Encode XML string literals.
static string encodeXMLString (string s, bool cdata)
 Encode XML string literals, optionally in CDATA sections.
static string decodeXMLString (string s)
 Decode XML string literals.
static string unescape (string s)
 remove escape characters from the specified string
static string unescape (string s, char b, char e)
 remove escape characters from the specified string

Private Member Functions

 XMLHelper ()
 private constructor to disable instantiation.

Detailed Description

XMLHelpder converts XML string literals.

Definition at line 47 of file XMLHelper.cs.


Constructor & Destructor Documentation

XMLStorage::XMLHelper::XMLHelper (  ) [inline, private]

private constructor to disable instantiation.

Definition at line 52 of file XMLHelper.cs.

        {
        }

Member Function Documentation

static string XMLStorage::XMLHelper::decodeXMLString ( string  s ) [inline, static]

Decode XML string literals.

Definition at line 116 of file XMLHelper.cs.

Referenced by XMLStorage::XMLStreamNode::getContent(), and XMLStorage::XMLNode::getContent().

        {
            StringBuilder buffer = new StringBuilder();

            for(int i = 0; i < s.Length; ++i)
            {
                char c = s[i];

                // handle string literals
                if (c == '&')
                {
                    if (string.Compare(s, i+1, "lt;", 0, 3, true) == 0)
                    {
                        buffer.Append('<');
                        i += 3;
                    }
                    if (string.Compare(s, i+1, "gt;", 0, 3, true) == 0)
                    {
                        buffer.Append('>');
                        i += 3;
                    }
                    if (string.Compare(s, i+1, "amp;", 0, 4, true) == 0)
                    {
                        buffer.Append('&');
                        i += 4;
                    }
                    if (string.Compare(s, i+1, "quot;", 0, 5, true) == 0)
                    {
                        buffer.Append('"');
                        i += 5;
                    }
                    if (string.Compare(s, i+1, "apos;", 0, 5, true) == 0)
                    {
                        buffer.Append('\'');
                        i += 5;
                    }
                    else
                        buffer.Append(c);
                }
                // handle CDATA sections
                else if (c=='<' && string.Compare(s, i+1, "![CDATA[", 0, 8)==0)
                {
                    int e = s.IndexOf("]]>", i+9);
                    if (e != -1)
                    {
                        i += 9;
                        int l = e - i;
                        buffer.Append(s.Substring(i, l));
                        i += 3;
                    }
                    else
                        buffer.Append(c);
                }
                else
                    buffer.Append(c);
            }

            return buffer.ToString();
        }
static string XMLStorage::XMLHelper::encodeXMLString ( string  s,
bool  cdata 
) [inline, static]

Encode XML string literals, optionally in CDATA sections.

Definition at line 67 of file XMLHelper.cs.

        {
            StringBuilder buffer = new StringBuilder();

            if (cdata)
            {
                buffer.Append("<![CDATA[");
                buffer.Append(s);
                buffer.Append("]]>");
            }
            else
            {
                foreach(char c in s)
                {
                    switch (c)
                    {
                        case '<':
                            buffer.Append("&lt;");
                            break;

                        case '>':
                            buffer.Append("&gt;");
                            break;

                        case '&':
                            buffer.Append("&amp;");
                            break;

                        case '"':
                            buffer.Append("&quot;");
                            break;

                        case '\'':
                            buffer.Append("&apos;");
                            break;

                        default:
                            buffer.Append(c);
                            break;
                    }
                }
            }

            return buffer.ToString();
        }
static string XMLStorage::XMLHelper::encodeXMLString ( string  s ) [inline, static]
static string XMLStorage::XMLHelper::unescape ( string  s ) [inline, static]

remove escape characters from the specified string

Definition at line 177 of file XMLHelper.cs.

References unescape().

Referenced by XMLStorage::XPathElement::parse(), and unescape().

        {
            return XMLHelper.unescape(s, '"', '"');
        }

Here is the call graph for this function:

static string XMLStorage::XMLHelper::unescape ( string  s,
char  b,
char  e 
) [inline, static]

remove escape characters from the specified string

Definition at line 183 of file XMLHelper.cs.

        {
            //  if (s.charAt(0) == b)
            //      s = s.substring(1);
            //
            //  if (s.Length>0 && end[-1]==e)
            //      s = s.substring(0, s.Length-1);

            if (s[0] == b)
                if (s.Length>1 && s[s.Length-1]==e)
                    s = s.Substring(1, s.Length-2);

            return s;
        }

The documentation for this class was generated from the following file: