Skip to content

stropho/illegal-xml-sanitizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Removes/replaces invalid XML chracters from strings

Motivation

In case you process data from unknown sources (like the internet) and you want to generate XML files with that data, let's say XLSX files, you need to sanize the input data. Otherwise you XML parser (the program that opens and nicely displayes XML files data) will most probably crash.

Usage

var xmlSanitize = require('');
//replace invalid characters by empty string
xmlSanitize("\uFFFFab", ''); // "ab"

//empty string is a default value so you could write just:
xmlSanitize("\uFFFFab"); // "ab"

Note, that if a surrogate pair character (\uD800-\uDFFF) is found, the following character is removed as well

About

Replace illegal XML characters from text content

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published