The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

YAX::Element - a DOM element node

SYNOPSIS

 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";

DESCRIPTION

This module represents element nodes in a YAX node tree.

METHODS

type

Returns the value of YAX::Constants::ELEMENT_NODE

name

Returns the tag name of this element.

next

Returns the next sibling if any.

prev

Returns the previous sibling if any.

parent

Returns the parent node if any.

attributes

Returns a hash ref of attributes.

children

Returns an array ref of child nodes.

append( $new_child )

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.

If this doesn't matter to you, then pushing or assigning directly to the children array ref is faster.

replace( $new_child, $ref_child )

Replaces $ref_child with $new_child. As above, this is preferred to assigning directly to the children array ref.

remove( $child )

Removes $child.

insert( $new_child, $ref_child )

Inserts $new_child before $ref_child and updates the parent field.

clone( $deep )

Clones the node. If $deep is true, then clones deeply.

query( $expr )

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.

For details on see YAX::Query.

as_string

Serializes this node. '""' is overloaded to call this method, so the following are equivalent:

 my $xml_str = $node->as_string;
 my $xml_str = "$node";

SEE ALSO

YAX:Node, YAX::Text, YAX::Fragment, YAX::Constants, YAX::Query

AUTHOR

 Richard Hundt

LICENSE

This program is free software and may be modified and distributed under the same terms as Perl itself.