sipxportlib  Version 3.3
Macros | Functions | Variables
XmlContent.cpp File Reference
#include "assert.h"
#include "utl/XmlContent.h"
#include "utl/UtlRegex.h"
Include dependency graph for XmlContent.cpp:

Macros

#define QUOTE   """ /* " \x22 */
 
#define AMPERSAND   "&" /* & \x26 */
 
#define APOSTROPHE   "'" /* ' \x27 */
 
#define LESS_THAN   "&lt;" /* < \x3c */
 
#define GREATER_THAN   "&gt;" /* > \x3e */
 
#define XML_CHARS   "[\\x09\\x0a\\x0d\\x20\\x21\\x23-\\x25\\x28-\\x3b\\x3d\\x3f-\\xff]"
 
#define ESC_CHARS   "[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x22\\x26\\x27\\x3c\\x3e]"
 

Functions

bool XmlEscape (UtlString &destination, const UtlString &source)
 Append escaped source string onto destination string. More...
 
bool XmlUnEscape (UtlString &destination, const UtlString &source)
 Append unescaped source string onto destination string. More...
 
bool XmlDecimal (UtlString &destination, int source, const char *format)
 Append decimal string onto destination string. More...
 

Variables

const RegEx CopyChars ("("XML_CHARS"*)("ESC_CHARS")?")
 

Macro Definition Documentation

#define QUOTE   "&quot;" /* " \x22 */

XmlContent provides conversion functions for escaping and unescaping UtlStrings as appropriate for use in XML attribute and element content.

At present, this makes no accomodation for character set differences; input is assumed to be 8 bits. The following characters are encoded using the mandatory character entities:

  • < => &lt;
  • & => &amp;
  • > => &gt;
  • ' => &apos;
  • " => &quot;

Other character values outside the range of valid 8-bit characters in XML:

  • #x09 | #x0A | #x0D | [#x20-#FF] are encoded using the numeric entity encoding (&#x??;).

While this is not strictly XML conformant (in that it does not explicitly deal with larger-size character encodings), it is symmetric (esaping and unescaping any 8 bit string using these routines will always produce the original string), and will interoperate correctly for any 8 bit encoding.

#define AMPERSAND   "&amp;" /* & \x26 */
#define APOSTROPHE   "&apos;" /* ' \x27 */
#define LESS_THAN   "&lt;" /* < \x3c */
#define GREATER_THAN   "&gt;" /* > \x3e */
#define XML_CHARS   "[\\x09\\x0a\\x0d\\x20\\x21\\x23-\\x25\\x28-\\x3b\\x3d\\x3f-\\xff]"
#define ESC_CHARS   "[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x22\\x26\\x27\\x3c\\x3e]"

Function Documentation

bool XmlEscape ( UtlString destination,
const UtlString source 
)

Append escaped source string onto destination string.

The contents of the source string are appended to the destination string, with all characters escaped as described above.

Returns
true for success, false if an error was returned from any UtlString operation.
bool XmlUnEscape ( UtlString destination,
const UtlString source 
)

Append unescaped source string onto destination string.

The contents of the source string are appended to the destination string, with all characters unescaped as described above.

Returns
true for success, false if an error was returned from any UtlString operation.
bool XmlDecimal ( UtlString destination,
int  source,
const char *  format 
)

Append decimal string onto destination string.

The source value is converted into a decimal string according to "format". The decimal string is appended to the destination string. "format" defaults to "%d", and must generate no more than 20 characters (excluding the ending NUL).

Returns
true for success, false if an error was returned from any UtlString operation.

Variable Documentation

const RegEx CopyChars("("XML_CHARS"*)("ESC_CHARS")?")