Fabric.js escapeXml() Method

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

zambiatek
Geeks<abc>for</abc>Geeks
zambiatek

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.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button