sanitize-xml
‘sanitize-xml’ simply sanitizes xml. Works in both Node.js and the browser. Lightweight. No dependencies.
Install
NPM
npm install sanitize-xml
CDN
<script type="text/javascript" src="https://cdn.rawgit.com/jackens/sanitize-xml/master/sanitize-xml.js"></script>
or
<script type="text/javascript" src="https://cdn.rawgit.com/jackens/sanitize-xml/master/sanitize-xml.min.js"></script>
or
<script type="text/javascript" src="https://unpkg.com/sanitize-xml/sanitize-xml.js"></script>
or
<script type="text/javascript" src="https://unpkg.com/sanitize-xml/sanitize-xml.min.js"></script>
Usage
var sanitizeXml = require('sanitize-xml')
sanitizeXml(someXmlString, options)
Defaults:
{
allowedTags: { a: { href: true }, b: {}, blockquote: {}, br: {}, del: {}, div: {}, em: {}, figcaption: {}, figure: {}, font: {}, h1: {}, h2: {}, h3: {}, h4: {}, h5: {}, h6: {}, hr: {}, i: {}, img: { src: true, alt: true }, li: {}, ol: {}, p: {}, s: {}, span: {}, strong: {}, sub: {}, sup: {}, table: {}, tbody: {}, td: {}, tfoot: {}, th: {}, thead: {}, tr: {}, u: {}, ul: {} },
caseInsensitiveTags: true,
caseInsensitiveAttributes: true,
removeComments: true,
disableProlog: true
}
More usage examples: https://github.com/jackens/sanitize-xml/blob/master/test.js.