Skip to content
lsl.devlsl.devLSL Dev

EscapeXML

EscapeXML
// Escape standard reserved XML chars with entities
// Copyright 2008, JB Kraft & Strife Onizuka
// Released under BSD license
// http://www.opensource.org/licenses/bsd-license.php


// ------------------------------------------------------------------------
// escape standard reserved XML chars with entities
// ------------------------------------------------------------------------
string escapeXML( string str )
{
    integer i = llStringLength( str );
    if(i)
    {
        string unescapedChars = "&\"'<>"; 
        list escapedChars = ["&amp;", "&quot;", "&#39;", "&lt;", "&gt;"];
        integer ndx;

        do
            if( ~(ndx = llSubStringIndex( unescapedChars, llGetSubString(str, --i, i))) )
                str = llInsertString( llDeleteSubString( str, i, i), i, llList2String( escapedChars, ndx));
        while(i);
    }
    return str;
}

// ------------------------------------------------------------------------
// D E F A U L T
// ------------------------------------------------------------------------
default
{
    state_entry()
    {
        llSay(0, escapeXML("<Black> & \"White\" & 'Red' & <Green>"));
    }
}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from EscapeXML, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.