LibXML::Writer

Raku bindings to the libxml2 streaming writer

class LibXML::Writer

Interface to libxml2 stream writer

use LibXML::Writer::Buffer; # write to a string

Methods

method have-writer

method have-writer() returns Bool

Ensure libxml2 has been compiled with the text-writer enabled

Indentation

method setIndented

method setIndented(
    Bool:D(Any):D $indented = Bool::True
) returns Mu

Enable or disable indentation

method setIndentString

method setIndentString(
    Str:D $indent
) returns Mu

Set indentation text

method setQuoteChar

method setQuoteChar(
    Str:D $quote
) returns Mu

Set character for quoting attributes

Document Methods

method startDocument

method startDocument(
    Str :$version,
    Str:D :$!enc = "UTF-8",
    Bool :$standalone
) returns Mu

Starts the document and writes the XML declaration

method endDocument

method endDocument() returns Mu

Closes any open elements or attributes and finishes the document

Element Methods

method startElement

method startElement(
    Str $name where { ... }
) returns Mu

Writes the specified start tag

method startElementNS

method startElementNS(
    Str $local-name where { ... },
    Str :$prefix,
    Str :$uri
) returns Mu

Writes the specified start tag and associates it with the given name-space and prefix

method endElement

method endElement() returns Mu

Closes the current element

method writeAttribute

method writeAttribute(
    Str $name where { ... },
    Str $content
) returns Mu

Writes an XML attribute, within an element

method writeAttributeNS

method writeAttributeNS(
    Str $local-name where { ... },
    Str $content,
    Str :$prefix,
    Str :$uri
) returns Mu

Writes an XML attribute with an associated name-space and prefix, within an element

method writeElement

method writeElement(
    Str $name where { ... },
    Str $content?
) returns Mu

Writes an atomic element; Either empty or with the given content

method writeElementNS

method writeElementNS(
    Str $local-name where { ... },
    Str $content = "",
    Str :$prefix,
    Str :$uri
) returns Mu

Writes an atomic element with an associated name-space and prefix

method writeComment

method writeComment(
    Str:D $content
) returns Mu

Writes an XML comment

method writeText

method writeText(
    Str:D $content
) returns UInt

Writes text content with escaping and encoding

$bytes-written = $writer.writeText: 'A&B'; # output: A&B

method writeCDATA

method writeCDATA(
    Str:D $content
) returns UInt

Writes CDATA formatted text content

$bytes-written = $writer.writeCDATA: 'A&B'; # output: <![CDATA[A&B]]>

multi method writeRaw

multi method writeRaw(
    Str:D $content
) returns Mu

Writes a string, with encoding

multi method writeRaw

multi method writeRaw(
    Blob[uint8]:D $content,
    Int $len where { ... } = Code.new
) returns Mu

Writes a pre-encoded buffer directly

method writePI

method writePI(
    Str $name where { ... },
    Str $content
) returns Mu

Writes an XML Processing Instruction

DTD Methods

method writeDTD

method writeDTD(
    Str $name where { ... },
    Str :$public-id,
    Str :$system-id,
    Str :$subset
) returns Mu

Writes an atomic XML DOCTYPE Definition (DTD)

method startDTD

method startDTD(
    Str $name where { ... },
    Str :$public-id,
    Str :$system-id
) returns Mu

Starts an XML DOCTYPE Definition (DTD)

The methods below can then be used to add definitions for DTD Elements, Attribute Lists, Entities and Notations, before calling endDTD.

method endDTD

method endDTD() returns Mu

Ends an XML DOCTYPE Definition (DTD)

method startDTDElement

method startDTDElement(
    Str $name where { ... }
) returns Mu

Starts an Element definition with an XML DTD

method endDTDElement

method endDTDElement() returns Mu

Ends an XML DTD element definition

method writeDTDElement

method writeDTDElement(
    Str $name where { ... },
    Str:D $content = "(EMPTY*)"
) returns Mu

Writes an Element declaration within an XML DTD

method writeDTDAttlist

method writeDTDAttlist(
    Str $name where { ... },
    Str $content
) returns Mu

Writes an Attribute List declaration within an XML DTD

method startDTDEntity

method startDTDEntity(
    Str $name where { ... },
    Int :$pe
) returns Mu

Starts an entity definition within an XML DTD

method endDTDEntity

method endDTDEntity() returns Mu

Ends an XML DTD Entity definition

method writeDTDInternalEntity

method writeDTDInternalEntity(
    Str $name where { ... },
    Str:D $content,
    Int :$pe
) returns Mu

Writes an Internal Entity definition within an XML DTD

method writeDTDExternalEntity

method writeDTDExternalEntity(
    Str $name where { ... },
    Str :$public-id,
    Str :$system-id,
    Str :$ndata,
    Int :$pe
) returns Mu

Writes an external entity definition within an XML DTD

method writeDTDNotation

method writeDTDNotation(
    Str $name where { ... },
    Str :$public-id,
    Str :$system-id
) returns Mu

Writes a notation definition within an XML DTD

method write

method write(
    $ast
) returns Mu

Write an AST struct

method flush

method flush() returns Mu

Flush an buffered XML

method close

method close() returns Mu

Finish writing XML. Flush output and free the native XML Writer

LibXML::Writer v0.0.1

Raku bindings to the libxml2 streaming writer

Authors

  • David Warring

License

Artistic-2.0

Dependencies

LibXML:ver<0.9.5+>

Test Dependencies

Provides

  • LibXML::Raw::TextWriter
  • LibXML::Writer
  • LibXML::Writer::Buffer
  • LibXML::Writer::Document
  • LibXML::Writer::File
  • LibXML::Writer::Node
  • LibXML::Writer::PushParser

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.