YAX
view release on metacpan or search on metacpan
lib/YAX/Node.pm view on Meta::CPAN
1;
__END__
=head1 NAME
=head1 DESCRIPTION
This module is used both as a base for L<YAX::Elememt>, L<YAX::Text>
and L<YAX::Fragment>. It is also partly mixed into L<YAX::Document>.
It is also used to represent comment, cdata sections and processing
instruction nodes.
=head1 METHODS
=over 4
=item type()
Returns the type of the node as a number in a way analogous to the
W3C DOM:
lib/YAX/Parser.pm view on Meta::CPAN
substr( $decl, 0, 4 ) eq '<!--' && do {
$offset = 4;
$length = $length - $offset - 3;
$type = COMMENT_NODE;
$name = '#comment';
};
substr( $decl, 0, 9 ) eq '<![CDATA[' && do {
$offset = 9;
$length = $length - $offset - 3;
$type = CDATA_SECTION_NODE;
$name = '#cdata';
};
substr( $decl, 0, 9 ) eq '<!DOCTYPE' && do {
$offset = 10;
$length = $length - $offset - 3;
$type = DOCUMENT_TYPE_NODE;
$name = "#document-type";
};
return $self->_mk_node(
$name, $type, substr( $decl, $offset, $length ), $parent
);
lib/YAX/Parser.pm view on Meta::CPAN
YAX::Parser - fast pure Perl tree and stream parser
=head1 SYNOPSIS
use YAX::Parser;
my $xml_str = <<XML
<?xml version="1.0" ?>
<doc>
<content id="42"><![CDATA[
This is a cdata section, so >>anything goes!<<
]]>
</content>
<!-- comments are nodes too -->
</doc>
XML
# tree parse - the common case
my $xml_doc = YAX::Parser->parse( $xml_str );
my $xml_doc = YAX::Parser->parse_file( $path );
lib/YAX/Query.pm view on Meta::CPAN
package YAX::Query;
use strict;
use YAX::Constants qw/:all/;
our $rx_iden = "[a-zA-Z0-9-\\:_]+|\\*";
our $rx_item = "\\[(?:(?:-?\\d+)|(?:\\d+\\s*\\.\\.\\s*-?\\d+))\\]";
our $rx_func = "\\b(?:parent|document|id)\\b\\(\\)";
our $rx_type = "#(?:text|processing-instruction|comment|cdata|node)";
our $rx_filt = "\\(.+?\\)(?:$rx_item)?(?=(?:\\.|\$))";
our $rx_attr = "@(?:$rx_iden)(?:$rx_item)?";
our $rx_elmt = "(?:$rx_iden)(?:$rx_item)?";
our $rx_term = "(?:$rx_type)(?:$rx_item)?|(?:$rx_func)(?:$rx_item)?";
our $rx_frag = "(?:$rx_attr)|(?:$rx_term)|(?:$rx_elmt)|(?:$rx_filt)";
our $rx_chld = "\\.(?:$rx_frag)";
our $rx_desc = "\\.\\.(?:$rx_frag)";
our $rx_expr = "$rx_desc|$rx_chld";
our $RX_TEST = "^(?:$rx_expr)+\$";
lib/YAX/Query.pm view on Meta::CPAN
}
elsif ( $token eq '*' ) {
$seen_flat && die "cannot select `$token' following `$seen_flat'";
push @exec, [ 'children', ELEMENT_NODE ];
}
elsif ( $token eq '#text' ) {
$seen_flat && die "cannot select `$token' following `$seen_flat'";
push @exec, [ 'children', TEXT_NODE ];
$seen_flat = $token;
}
elsif ( $token eq '#cdata' ) {
$seen_flat = $token;
push @exec, [ 'children', CDATA_SECTION_NODE ];
}
elsif ( $token eq '#processing-instruction' ) {
$seen_flat && die "cannot select `$token' following `$seen_flat'";
push @exec, [ 'children', PROCESSING_INSTRUCTION_NODE ];
}
elsif ( $token eq '#comment' ) {
$seen_flat && die "cannot select `$token' following `$seen_flat'";
push @exec, [ 'children', COMMENT_NODE ];
lib/YAX/Query.pm view on Meta::CPAN
parent nodes of the set
=item '.#text'
all text children
=item '.#processing-instruction'
all processing instruction children
=item '.#cdata'
all CDATA children
=item '.#node'
all child nodes of
=item '.#comment'
all comment children of
lib/YAX/Query.pm view on Meta::CPAN
# or the equivalent
@ids = grep { filter( $_ ) } @{ $q->select('..div.*') };
=item parent()
See `.parent()' above
=item children( $type )
Selects child nodes of type $type (see L<YAX::Constants> for valid types).
The `#text', `#cdata', `#processing-instruction' and `#comment' selectors
are implemented with C<children(...)>.
=item child( $name )
Selects elements named $name.
=item attribute( $name )
Selects attribute values named $name.
( run in 0.511 second using v1.01-cache-2.11-cpan-454fe037f31 )