Open In App

Fabric.js escapeXml() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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("GeeksforGeeks"));
          
        // 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:

GeeksforGeeks
Geeks<abc>for</abc>Geeks
GeeksforGeeks

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.


Last Updated : 05 Jan, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads