The escapeXml() method is used to escape the characters of the XML markup language present in the specified string.
Syntax:
escapeXml(string)
Parameters: This method accepts a parameter as mentioned above and described below:
- string: This parameter holds the string to escape.
Return Value: This method returns the escaped version of the specified string.
Example 1:
Javascript
<!DOCTYPE html> <html> <head> <script src= </script> <script type= "text/javascript" src= </script> <script type= "text/javascript" src= </script> </head> <body> <script type= "text/javascript" > // Printing a string with the help // of escapeXml() function // without the characters of XML console.log(fabric.util.string.escapeXml( "neveropen" )); // Printing a string with the help // of escapeXml() function // with the characters of XML console.log(fabric.util.string.escapeXml( "Geeks<abc>for</abc>Geeks" )); // Printing a string without the help // of escapeXml() function // with the characters of XML console.log( "Geeks<abc>for</abc>Geeks" ); </script> </body> </html> |
Output:
neveropen Geeks<abc>for</abc>Geeks neveropen
Example 2:
Javascript
<!DOCTYPE html> <html> <head> <script src= </script> <script type= "text/javascript" src= </script> <script type= "text/javascript" src= </script> </head> <body> <script type= "text/javascript" > console.log( "Using escapeXml() Function:" ); var value= "GFG <a> is a CS </a> portal." ; console.log(fabric.util.string.escapeXml(value)); console.log( "Without using escapeXml() Function:" ); var value= "GFG <a> is a CS </a> portal." ; console.log(value); </script> </body> </html> |
Output:
Using escapeXml() Function: GFG <a> is a CS </a> portal. Without using escapeXml() Function: GFG is a CS portal.