The manakai project

Web::XML::Serializer

Serialization of XML DOM

SYNOPSIS

  warn $element->inner_html;
  warn $document->inner_html;

DESCRIPTION

The Web::XML::Serializer module provides a function that implements the fragment serialization algorithm in the HTML Standard. It can be used to serialize an XML Document, Element, or DocumentFragment node into an XML document or fragment.

Note that the algorithm cannot be used to serialize an arbitrary DOM tree; an attempt to serialize a DOM that cannot be represented in a static XML document (fragment) will result in an ill-formed document or in a document representing different DOM tree.

For example, the DOM tree:

  +- Element |p|
       +- Comment |ho --><!-- ge|

... cannot be represented in XML serialization. The serialization algorithm will generate a well-formed XML fragment:

  <p><!--ho --><!-- ge--></p>

... but it represents another DOM tree:

  +- Element |p|
       +- Comment |ho |
       +- Comment | ge|

... without raising any error or warning. This is a limitation of the XML serialization format.

NOTE: Usually you don't have to call this module directly, since Web::DOM::Document and Web::DOM::Element modules implement the inner_html attribute for DOM Document and Element nodes.

METHODS

There are following methods:

$serializer = Web::XML::Serializer->new

Return a new instance of the serializer.

$scalarref = $serializer->get_inner_html ($node)

Serialize the specified node using the XML fragment serialization algorithm. The result is returned as a reference to the character string.

The argument must be a DOM Document, Document, or DocumentFragment.

SPECIFICATIONS

HTML

HTML Standard <https://html.spec.whatwg.org/#serializing-xhtml-fragments>.

DOMPARSING

DOM Parsing and Serialization Standard <https://domparsing.spec.whatwg.org/#concept-serialize-xml>.

SEE ALSO

Web::HTML::Serializer.

Web::DOM::ParentNode.

Namespace fixup <https://suika.suikawiki.org/www/markup/xml/nsfixup>.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2007-2016 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.