XMLHelpder converts XML string literals. More...
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. | |
XMLHelpder converts XML string literals.
Definition at line 47 of file XMLHelper.cs.
| XMLStorage::XMLHelper::XMLHelper | ( | ) | [inline, private] |
| 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("<");
break;
case '>':
buffer.Append(">");
break;
case '&':
buffer.Append("&");
break;
case '"':
buffer.Append(""");
break;
case '\'':
buffer.Append("'");
break;
default:
buffer.Append(c);
break;
}
}
}
return buffer.ToString();
}
| static string XMLStorage::XMLHelper::encodeXMLString | ( | string | s ) | [inline, static] |
Encode XML string literals.
Definition at line 59 of file XMLHelper.cs.
Referenced by XMLStorage::XMLStreamReader::characters(), XMLStorage::XMLDocReader::characters(), XMLStorage::XMLNode::prettyWriteWorker(), XMLStorage::XMLStreamWriter::setContent(), XMLStorage::XMLNode::setContent(), XMLStorage::XMLNode::smartWriteWorker(), XMLStorage::XMLStreamWriter::writeAttributes(), XMLStorage::XMLStreamWriter::writePost(), XMLStorage::XMLStreamWriter::writePre(), and XMLStorage::XMLNode::writeWorker().
{
return encodeXMLString(s, false);
}
| 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, '"', '"');
}

| 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;
}
1.7.2