Coder Social home page Coder Social logo

dokraus / xmlserializer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cburgmer/xmlserializer

0.0 1.0 0.0 128 KB

xmlserializer serializes a DOM subtree or DOM document into XML/XHTML

Home Page: http://cburgmer.github.io/xmlserializer/

License: MIT License

HTML 10.87% JavaScript 89.13%

xmlserializer's Introduction

xmlserializer serializes a DOM subtree or DOM document into XML/XHTML. NPM version

It understands documents generated by parse5 and regular browser DOMs (and thus can act as a drop-in replacement for XMLSerializer which for some browsers only serializes true XML documents).

Limitations

See the 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 http://cburgmer.github.io/xmlserializer/

Run tests and build for the browser

$ npm install && npm test

Build Status

Example

For a browser based example run npm test and see example.html.

The same code for Node.js:

var xmlserializer = require('xmlserializer');
var html2xhtml = function (htmlString) {
    var parser = require('parse5'),
        dom = parser.parse(htmlString);

    return xmlserializer.serializeToString(dom);
};
console.log(html2xhtml('<br>'));
// => <html xmlns="http://www.w3.org/1999/xhtml"><head/><body><br/></body></html>

xmlserializer's People

Contributors

cburgmer avatar kevinoid avatar mike-schultz avatar

Watchers

Dominik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.