Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cburgmer/xmlserializer
xmlserializer serializes a DOM subtree or DOM document into XML/XHTML
https://github.com/cburgmer/xmlserializer
Last synced: about 1 month ago
JSON representation
xmlserializer serializes a DOM subtree or DOM document into XML/XHTML
- Host: GitHub
- URL: https://github.com/cburgmer/xmlserializer
- Owner: cburgmer
- License: mit
- Created: 2013-11-13T07:03:34.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-01-28T16:29:25.000Z (almost 2 years ago)
- Last Synced: 2024-05-28T04:01:07.138Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 177 KB
- Stars: 36
- Watchers: 4
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
xmlserializer serializes a DOM subtree or DOM document into XML/XHTML.
It understands documents generated by [parse5](https://github.com/inikulin/parse5) and regular browser DOMs (and thus can act as a drop-in replacement for [XMLSerializer](https://developer.mozilla.org/en/docs/XMLSerializer) which for some browsers only serializes true XML documents).
Limitations
-----------See [the wiki](https://github.com/cburgmer/xmlserializer/wiki) for limitations in HTML to XML conversion.
Currently some cases are treated differently to the XMLSerializer implementation of the browsers:
- Invalid characters (ASCII control characters) that are invalid in XML 1.0 are removed on serialization. The browsers silently include those characters and on reparsing those documents throw a parser exception.
- Dashes in comments are escaped to provide valid comments in XHTML. Firefox does not do this.
- The `xmlns` attribute has higher precedence than the type of the DOM object passed to the serializer.
- Small differences in style: no space in self-closing tag, empty value for boolean attributes, quoting of single apostrophes in attribute values.This behaviour might become optional in the future.
Demo
----See https://runkit.com/embed/siinwcyjdcjw
Run tests and build for the browser
-----------------------------------$ npm install && npm test
[![Build Status](https://travis-ci.org/cburgmer/xmlserializer.svg?branch=master)](https://travis-ci.org/cburgmer/xmlserializer)
Example
-------For a browser based example run `npm test` and see `example.html`.
The same code for Node.js:
```js
var xmlserializer = require('xmlserializer');
var html2xhtml = function (htmlString) {
var parser = require('parse5'),
dom = parser.parse(htmlString);return xmlserializer.serializeToString(dom);
};
console.log(html2xhtml('
'));
// =>
```