YAX::Element - a DOM element node
use YAX::Element; # construct my $elmt = YAX::Element->new( $name, %attr ); # access an attribute $elmt->attributes->{foo} = 'bar'; $elmt->{foo} = 'bar'; # same as above, '%{}' is overloaded # access a child my $chld = $elmt->children->[2]; my $chld = $elmt->[2]; # same as above, '@{}' is overloaded # access the parent my $prnt = $elmt->parent; # access siblings my $next = $elmt->next; my $prev = $elmt->prev; # manipulation $elmt->append( $new_child ); $elmt->remove( $old_child ); $elmt->replace( $new_child, $ref_child ); $elmt->insert ( $new_child, $ref_child ); # cloning my $copy = $elmt->clone( $deep ); # querying my $list = $elmt->query( $expr ); # misc my $name = $elmt->name; # tag name my $type = $elmt->type; # YAX::Constants::ELEMENT_NODE # stringify my $xstr = $elmt->as_string; my $xstr = "$elmt";
This module represents element nodes in a YAX node tree.
Returns the value of YAX::Constants::ELEMENT_NODE
Returns the tag name of this element.
Returns the next sibling if any.
Returns the previous sibling if any.
Returns the parent node if any.
Returns a hash ref of attributes.
Returns an array ref of child nodes.
Appends $new_child to this node. This is preferred over:
push @$elmt, $child;
because the append(...) makes sure that the $child knows about its new parent, and removes it from any existing parent first.
append(...)
$child
If this doesn't matter to you, then pushing or assigning directly to the children array ref is faster.
Replaces $ref_child with $new_child. As above, this is preferred to assigning directly to the children array ref.
$ref_child
$new_child
Removes $child.
Inserts $new_child before $ref_child and updates the parent field.
Clones the node. If $deep is true, then clones deeply.
$deep
Returns a query list object containing nodes which match the query expression $expr. If $expr is not defined, then still returns a query list object which can be used for chaining.
$expr
For details on see YAX::Query.
Serializes this node. '""' is overloaded to call this method, so the following are equivalent:
my $xml_str = $node->as_string; my $xml_str = "$node";
YAX:Node, YAX::Text, YAX::Fragment, YAX::Constants, YAX::Query
Richard Hundt
This program is free software and may be modified and distributed under the same terms as Perl itself.
To install YAX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm YAX
CPAN shell
perl -MCPAN -e shell install YAX
For more information on module installation, please visit the detailed CPAN module installation guide.