view release on metacpan or search on metacpan
- interface to libxml2's pull-parser XML::LibXML::Reader
(initiated by Heiko Klein)
- make error messages intended to the user report the line of the
application call rather than that of the internal XS call
- XML::LibXML::Attr->serializeContent added (convenience function)
- fix getAttributeNode etc. w.r.t. #FIXED attributes (as well as some
cases with old buggy libxml2 versions)
- warn if runtime libxml2 is older than the one used at the compile time
- if compiled against libxml2 >= 2.6.27, new parse_html_* implementation is used
allowing encoding and other options to be passed to the parser
- DOM-compliant nodeNames: #comment, #text, #cdata, #document, #document-fragment
- toString on empty text node returns empty string, not undef
- cloneNode copies attributes on an element as required by the DOM spec
1.61 Unknown
- get{Elements,Children}By{TagName,TagNameNS,LocalName} now
obey wildcards '*', getChildrenByLocalName was added.
- XML::LibXML::XPathContext merged in
- many new tests added
- the module should now be fully compatibile with libxml2 >= 2.6.16
(some older versions compile but have problems with namespaced attributes)
complete_attributes => XML_PARSE_DTDATTR,
validation => XML_PARSE_DTDVALID,
suppress_errors => XML_PARSE_NOERROR,
suppress_warnings => XML_PARSE_NOWARNING,
pedantic_parser => XML_PARSE_PEDANTIC,
no_blanks => XML_PARSE_NOBLANKS,
expand_xinclude => XML_PARSE_XINCLUDE,
xinclude => XML_PARSE_XINCLUDE,
no_network => XML_PARSE_NONET,
clean_namespaces => XML_PARSE_NSCLEAN,
no_cdata => XML_PARSE_NOCDATA,
no_xinclude_nodes => XML_PARSE_NOXINCNODE,
old10 => XML_PARSE_OLD10,
no_base_fix => XML_PARSE_NOBASEFIX,
huge => XML_PARSE_HUGE,
oldsax => XML_PARSE_OLDSAX,
);
my %OUR_FLAGS = (
recover => 'XML_LIBXML_RECOVER',
line_numbers => 'XML_LIBXML_LINENUMBERS',
# or recover_silently flags as per the following excerpt from the manpage:
# </quote>
if ($self->recover_silently)
{
$flags |= 32;
}
$flags |= 64 if $opts->{suppress_warnings};
$flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser;
$flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks;
$flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : !$self->no_network;
$flags |= 16384 if $opts->{no_cdata};
$flags |= 65536 if $opts->{compact}; # compact small text nodes; no modification
# of the tree allowed afterwards
# (WILL possibly CRASH IF YOU try to MODIFY THE TREE)
$flags |= 524288 if $opts->{huge}; # relax any hardcoded limit from the parser
$flags |= 1048576 if $opts->{oldsax}; # parse using SAX2 interface from before 2.7.0
return ($opts->{URI},$opts->{encoding},$flags);
}
sub parse_html_string {
docs/libxml.dbk view on Meta::CPAN
</varlistentry>
<varlistentry>
<term>clean_namespaces</term>
<listitem>
<para>/parser, reader/</para>
<para>remove redundant namespaces declarations during parsing; possible values are 0 and 1.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>no_cdata</term>
<listitem>
<para>/parser, html, reader/</para>
<para>merge CDATA as text nodes; possible values are 0 and 1</para>
</listitem>
</varlistentry>
<varlistentry>
<term>no_basefix</term>
<listitem>
<para>/parser, reader/</para>
<para>not fixup XINCLUDE xml#base URIS; possible values are 0 and 1</para>
docs/libxml.dbk view on Meta::CPAN
<para>This function creates a DocumentFragment.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>createCDATASection</term>
<listitem>
<funcsynopsis>
<funcsynopsisinfo>$cdata = $dom->createCDATASection( $cdata_content );</funcsynopsisinfo>
</funcsynopsis>
<para>Similar to createTextNode and createComment, this function creates a CDataSection bound to the current DOM.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>createProcessingInstruction</term>
<listitem>
docs/libxml.dbk view on Meta::CPAN
<funcsynopsis>
<funcsynopsisinfo>$name = $node->nodeName;</funcsynopsisinfo>
</funcsynopsis>
<para>Returns the node's name. This function is
aware of namespaces and returns the full name of
the current node (<function>prefix:localname</function>).
</para>
<para>Since 1.62 this function also returns the correct
DOM names for node types with constant names, namely:
#text, #cdata-section, #comment, #document,
#document-fragment.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>setNodeName</term>
<listitem>
<funcsynopsis>
docs/libxml.dbk view on Meta::CPAN
<varlistentry>
<term>setData($string)</term>
<listitem>
<funcsynopsis>
<funcsynopsisinfo>$text->setData( $text_content );</funcsynopsisinfo>
</funcsynopsis>
<para>This function sets or replaces text content to a node. The node has to be of the type "text", "cdata" or
"comment".</para>
</listitem>
</varlistentry>
<varlistentry>
<term>substringData($offset,$length)</term>
<listitem>
case XML_NOTATION_NODE :
case XML_NAMESPACE_DECL :
name = node->name;
break;
case XML_COMMENT_NODE :
name = (const xmlChar *) "#comment";
break;
case XML_CDATA_SECTION_NODE :
name = (const xmlChar *) "#cdata-section";
break;
case XML_TEXT_NODE :
name = (const xmlChar *) "#text";
break;
case XML_DOCUMENT_NODE :
case XML_HTML_DOCUMENT_NODE :
case XML_DOCB_DOCUMENT_NODE :
example/test.html view on Meta::CPAN
$docstring = $dom->toString([$format]);
$bool = $dom->is_valid();
$root = $dom->getDocumentElement($name, $namespace );
$dom->setDocumentElement( $root );
$element = $dom->createElement( $nodename );
$element = $dom->createElementNS( $namespaceURI, $qname );
$text = $dom->createTextNode( $content_text );
$comment = $dom->createComment( $comment_text );
$attrnode = $doc->createAttribute($name [,$value]);
$attrnode = $doc->createAttributeNS( namespaceURI, $name [,$value] );
$cdata = $dom->create( $cdata_content );
$document->importNode( $node [, $move] );
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The Document Class is the result of a parsing process. But sometimes it is
necessary to create a Document from scratch. The DOM Document Class
provides functions that are conform to the DOM Core naming style. It
inherits all functions from <EM>XML::LibXML::Node</EM> as specified in DOM Level2. This enables to access the nodes beside the
example/test.xhtml view on Meta::CPAN
$docstring = $dom->toString([$format]);
$bool = $dom->is_valid();
$root = $dom->getDocumentElement($name, $namespace );
$dom->setDocumentElement( $root );
$element = $dom->createElement( $nodename );
$element = $dom->createElementNS( $namespaceURI, $qname );
$text = $dom->createTextNode( $content_text );
$comment = $dom->createComment( $comment_text );
$attrnode = $doc->createAttribute($name [,$value]);
$attrnode = $doc->createAttributeNS( namespaceURI, $name [,$value] );
$cdata = $dom->create( $cdata_content );
$document->importNode( $node [, $move] );
</pre><p/><hr/><h1><a name="DESCRIPTION">DESCRIPTION</a></h1><p>
The Document Class is the result of a parsing process. But sometimes it is
necessary to create a Document from scratch. The DOM Document Class
provides functions that are conform to the DOM Core naming style. It
inherits all functions from <em>XML::LibXML::Node</em> as specified in DOM Level2. This enables to access the nodes beside the
root element on document level - a <em>DTD</em> for example. The support for these nodes is limited at the moment, so I
would recommend, not to use <em>node</em> functions on <em>documents</em>. It is suggested that one should always create a node not bound to any
document. There is no need of really including the node to the document,
but once the node is bound to a document, it is quite safe that all strings
lib/XML/LibXML/Document.pod view on Meta::CPAN
$dom->validate();
$root = $dom->documentElement();
$dom->setDocumentElement( $root );
$element = $dom->createElement( $nodename );
$element = $dom->createElementNS( $namespaceURI, $nodename );
$text = $dom->createTextNode( $content_text );
$comment = $dom->createComment( $comment_text );
$attrnode = $doc->createAttribute($name [,$value]);
$attrnode = $doc->createAttributeNS( namespaceURI, $name [,$value] );
$fragment = $doc->createDocumentFragment();
$cdata = $dom->createCDATASection( $cdata_content );
my $pi = $doc->createProcessingInstruction( $target, $data );
my $entref = $doc->createEntityReference($refname);
$dtd = $document->createInternalSubset( $rootnode, $public, $system);
$dtd = $document->createExternalSubset( $rootnode_name, $publicId, $systemId);
$document->importNode( $node );
$document->adoptNode( $node );
my $dtd = $doc->externalSubset;
my $dtd = $doc->internalSubset;
$doc->setExternalSubset($dtd);
$doc->setInternalSubset($dtd);
lib/XML/LibXML/Document.pod view on Meta::CPAN
=item createDocumentFragment
$fragment = $doc->createDocumentFragment();
This function creates a DocumentFragment.
=item createCDATASection
$cdata = $dom->createCDATASection( $cdata_content );
Similar to createTextNode and createComment, this function creates a
CDataSection bound to the current DOM.
=item createProcessingInstruction
my $pi = $doc->createProcessingInstruction( $target, $data );
create a processing instruction node.
lib/XML/LibXML/Node.pod view on Meta::CPAN
=over 4
=item nodeName
$name = $node->nodeName;
Returns the node's name. This function is aware of namespaces and returns the
full name of the current node (C<<<<<< prefix:localname >>>>>>).
Since 1.62 this function also returns the correct DOM names for node types with
constant names, namely: #text, #cdata-section, #comment, #document,
#document-fragment.
=item setNodeName
$node->setNodeName( $newName );
In very limited situations, it is useful to change a nodes name. In the DOM
specification this should throw an error. This Function is aware of namespaces.
lib/XML/LibXML/Parser.pod view on Meta::CPAN
=item clean_namespaces
/parser, reader/
remove redundant namespaces declarations during parsing; possible values are 0
and 1.
=item no_cdata
/parser, html, reader/
merge CDATA as text nodes; possible values are 0 and 1
=item no_basefix
/parser, reader/
lib/XML/LibXML/SAX/Builder.pm view on Meta::CPAN
sub end_element {
my ($self, $el) = @_;
return unless $self->{Parent};
$self->{NamespaceStack}->pop_context;
$self->{Parent} = $self->{Parent}->parentNode();
return ();
}
sub start_cdata {
my $self = shift;
$self->{IN_CDATA} = 1;
return ();
}
sub end_cdata {
my $self = shift;
$self->{IN_CDATA} = 0;
return ();
}
sub characters {
my ($self, $chars) = @_;
if ( not defined $self->{DOM} and not defined $self->{Parent} ) {
$self->{Parent} = XML::LibXML::DocumentFragment->new();
$self->{NamespaceStack} = XML::NamespaceSupport->new;
lib/XML/LibXML/Text.pod view on Meta::CPAN
$text->nodeValue;
will have the same result and are not different entities.
=item setData($string)
$text->setData( $text_content );
This function sets or replaces text content to a node. The node has to be of
the type "text", "cdata" or "comment".
=item substringData($offset,$length)
$text->substringData($offset, $length);
Extracts a range of data from the node. (DOM Spec) This function takes the two
parameters $offset and $length and returns the sub-string, if available.
If the node contains no data or $offset refers to an non-existing string index,
perl-libxml-sax.c view on Meta::CPAN
PSaxCharactersFlush(ctxt, sax->charbuf);
}
ENTER;
SAVETMPS;
PUSHMARK(SP) ;
XPUSHs(handler);
PUTBACK;
call_method( "start_cdata", G_SCALAR | G_EVAL | G_DISCARD );
if (SvTRUE(ERRSV)) {
croak_obj;
}
SPAGAIN;
PUSHMARK(SP) ;
XPUSHs(handler);
element = PmmGenCharDataSV(aTHX_ sax, ch, len);
perl-libxml-sax.c view on Meta::CPAN
if (SvTRUE(ERRSV)) {
croak_obj;
}
SPAGAIN;
PUSHMARK(SP) ;
XPUSHs(handler);
PUTBACK;
call_method( "end_cdata", G_SCALAR | G_EVAL | G_DISCARD );
sv_2mortal(rv);
if (SvTRUE(ERRSV)) {
croak_obj;
}
FREETMPS ;
LEAVE ;
}
perl-libxml-sax.c view on Meta::CPAN
*/
retval->endDocument = NULL; /* (endDocumentSAXFunc)&PSaxEndDocument; */
retval->startElement = (startElementSAXFunc)&PSaxStartElement;
retval->endElement = (endElementSAXFunc)&PSaxEndElement;
retval->characters = (charactersSAXFunc)&PSaxCharacters;
retval->ignorableWhitespace = (ignorableWhitespaceSAXFunc)&PSaxCharacters;
retval->comment = (commentSAXFunc)&PSaxComment;
retval->cdataBlock = (cdataBlockSAXFunc)&PSaxCDATABlock;
retval->processingInstruction = (processingInstructionSAXFunc)&PSaxProcessingInstruction;
/* warning functions should be internal */
retval->warning = (warningSAXFunc)&PmmSaxWarning;
retval->error = (errorSAXFunc)&PmmSaxError;
retval->fatalError = (fatalErrorSAXFunc)&PmmSaxFatalError;
retval->externalSubset = (externalSubsetSAXFunc)&PSaxExternalSubset;
t/02parse.t view on Meta::CPAN
my @good_strings = ("<foo>", "bar", "</foo>" );
my %bad_strings = (
predocend1 => ["<A>" ],
predocend2 => ["<A>", "B"],
predocend3 => ["<A>", "<C>"],
predocend4 => ["<A>", "<C/>"],
postdocend1 => ["<A/>", "<C/>"],
# use with libxml2 2.4.26: postdocend2 => ["<A/>", "B"], # libxml2 < 2.4.26 bug
postdocend3 => ["<A/>", "BB"],
badcdata => ["<A> ","<!","[CDATA[B]","</A>"],
badending1 => ["<A> ","B","</C>"],
badending2 => ["<A> ","</C>","</A>"],
);
my $parser = XML::LibXML->new;
{
for ( @good_strings ) {
$parser->parse_chunk( $_ );
}
my $doc = $parser->parse_chunk("",1);
# TEST:$count=2;
foreach my $arg_to_parse ($string, \$string)
{
my $doc = XML::LibXML->load_xml(string=>$arg_to_parse);
my $r = $doc->getDocumentElement;
# TEST*$count
ok($r, ' TODO : Add test name');
my @nonblank = $r->nonBlankChildNodes;
# TEST*$count
is(join(',',map $_->nodeName,@nonblank), 'a,b,#comment,#cdata-section,foo,c,#text', ' TODO : Add test name' );
# TEST*$count
is($r->firstChild->nodeName, '#text', ' TODO : Add test name');
my @all = $r->childNodes;
# TEST*$count
is(join(',',map $_->nodeName,@all), '#text,a,#text,b,#text,#cdata-section,#text,#comment,#text,#cdata-section,#text,foo,#text,c,#text', ' TODO : Add test name' );
my $f = $r->firstNonBlankChild;
my $p;
# TEST*$count
is($f->nodeName, 'a', ' TODO : Add test name');
# TEST*$count
is($f->nextSibling->nodeName, '#text', ' TODO : Add test name');
# TEST*$count
is($f->previousSibling->nodeName, '#text', ' TODO : Add test name');
# TEST*$count
}
{
# CDATA node name test
my $node = XML::LibXML::CDATASection->new("test");
# TEST
is( $node->string_value(), "test", ' TODO : Add test name' );
# TEST
is( $node->nodeName(), "#cdata-section", ' TODO : Add test name' );
}
{
# Comment node name test
my $node = XML::LibXML::Comment->new("test");
# TEST
is( $node->string_value(), "test", ' TODO : Add test name' );
# TEST
t/11memory.t view on Meta::CPAN
my $self = shift;
my $dummy = shift;
# warn Dumper( $dummy );
}
sub end_element {
my $self = shift;
my $dummy = shift;
}
sub start_cdata {
my $self = shift;
my $dummy = shift;
}
sub end_cdata {
my $self = shift;
my $dummy = shift;
}
sub start_prefix_mapping {
my $self = shift;
my $dummy = shift;
}
sub end_prefix_mapping {
<![CDATA[ a < b ]]>
</root>
EOT
my $expecting = [
start_document => [ 2, 1 ],
start_element => [ 2, 6 ],
characters => [ 4, 1 ],
comment => [ 4, 17 ],
characters => [ 5, 1 ],
start_cdata => [ 5, 20 ],
characters => [ 5, 20 ],
end_cdata => [ 5, 20 ],
characters => [ 6, 1 ],
end_element => [ 6, 8 ],
end_document => [ 6, 8 ],
];
# TEST
is_deeply( \@stack, $expecting, "Check locator positions" );
}
package SAXLocatorTester;
use Test::More;
sub new {
my ($class, $cb) = @_;
my $self = bless {}, $class;
for my $method ( qw(
start_document end_document
start_element end_element
start_cdata end_cdata
start_dtd end_dtd
characters
comment
) ) {
no strict 'refs';
*$method = sub { $cb->( $_[0], $method, @_[1..$#_]) };
}
return $self;
}
t/43options.t view on Meta::CPAN
complete_attributes
validation
suppress_errors
suppress_warnings
pedantic_parser
no_blanks
expand_xinclude
xinclude
no_network
clean_namespaces
no_cdata
no_xinclude_nodes
old10
no_base_fix
huge
oldsax
line_numbers
URI
base_uri
gdome
);