XML-Stream

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

  - Upgraded the XPath engine to a more extensible and robust
    design.
  - To get tests to work 100% I have to get better determination
    on the BuildXML functions.  So fomr this point on, all
    attributes are printed in alphabetical order.
  - Fixed bug in Parser with <![CDATA[...]]> not being supported.
  - Changed BuildXML for Tree.  You have to pass it a ref
    and not an array.  That was to make the rawXML thing
    work better.
  - Added the ability to add raw XML at the BuildXML call.
  - Added remove_cdata method to Node.
  - Added methods to Node to make calls easier (XPath, GetXML).

1.15
====
  - Added XPath function and support for most of the abbreviated
    xpaths.
  - Added new XML::Stream::Node type.  This behaves more like a
    you would think an XML node would behave.
  - Added a NONBLOCKING variable to control if the parser blocks
    or does not block.  This might cause some problems, but it also

MANIFEST  view on Meta::CPAN

lib/XML/Stream/XPath/Query.pm
lib/XML/Stream/XPath/Value.pm
LICENSE
Makefile.PL
MANIFEST			This list of files
META.json
META.yml
README
t/0-signature.t
t/buildxml.t
t/cdata.t
t/load.t
t/memory_cycle.t
t/net_xmpp.t
t/parse_node.t
t/parse_tree.t
t/quotes.t
t/tcpip.t
t/tcpip2ssl.t
t/test.xml
t/xml2config.t

SIGNATURE  view on Meta::CPAN

SHA1 17d0f2d0c61af08a5331cdfd5bd839d58c993489 lib/XML/Stream/Parser.pm
SHA1 3a369f4ec19f87441ea11ba9e617dd449a05c820 lib/XML/Stream/Parser/DTD.pm
SHA1 ffe36acb769a8408c0c82b9f2f9b089ae8a50831 lib/XML/Stream/Tools.pm
SHA1 f60a701eda50942a8de00e21c6ab07af1bd3ff2e lib/XML/Stream/Tree.pm
SHA1 691d6c822e434d28159d175d259a8f4436bc79cf lib/XML/Stream/XPath.pm
SHA1 aa8f58a1ac65c303f302ec86e3c52d48da35fcac lib/XML/Stream/XPath/Op.pm
SHA1 1f4fb71bc08b45e1af29e16e5a827a728a4b532c lib/XML/Stream/XPath/Query.pm
SHA1 fa6f0b83e6c3e9d9ce30c8d3d5f55c309c2ac6d7 lib/XML/Stream/XPath/Value.pm
SHA1 850e2740a75782524068bf075c62dce17b6097d9 t/0-signature.t
SHA1 2d39967d76139beb8af25377d4a6c51d7bcb5b76 t/buildxml.t
SHA1 ed3c8cf8b15161f0584c3b37a66de39963358e35 t/cdata.t
SHA1 53a1b80e7a605c905e8bccba2ce0ab65182b5648 t/load.t
SHA1 94a8c53a14c1771ab1b4a5daf331a7cbaed07766 t/memory_cycle.t
SHA1 5f335ada56c5454226e78d0a83b055b24f64a2c4 t/net_xmpp.t
SHA1 c783fee53c26174b36405469041b59aadd816bb0 t/parse_node.t
SHA1 da1f249867d9b27201b2157f0db7a3ee252ad4c4 t/parse_tree.t
SHA1 1bdcc7aaf3b3377f0966976c6d52f243b5fe2fb4 t/quotes.t
SHA1 416b6a366a45b581886130d4d6ecabfc953ff893 t/tcpip.t
SHA1 721484da679b9a4e684001845831f617d7deed96 t/tcpip2ssl.t
SHA1 191c3a9c3eeca7b58b096436ee241342e6984d2f t/test.xml
SHA1 734b87f26e0f144ed9ad207649c893d153495885 t/xml2config.t

lib/XML/Stream.pm  view on Meta::CPAN


    foreach my $module (@_)
    {
        eval "use XML::Stream::$module;";
        die($@) if ($@);

        my $lc = lc($module);
        
        eval("\$HANDLERS{\$lc}->{startElement} = \\&XML::Stream::${module}::_handle_element;");
        eval("\$HANDLERS{\$lc}->{endElement}   = \\&XML::Stream::${module}::_handle_close;");
        eval("\$HANDLERS{\$lc}->{characters}   = \\&XML::Stream::${module}::_handle_cdata;");
    }
}

=pod

=head2 new


  new(
      debug      => string,

lib/XML/Stream/Node.pm  view on Meta::CPAN

The result of parsing:

  <foo><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>

would be:

  [ tag:       foo
    att:       {}
    children:  [ tag:      head
                 att:      {id=>"a"}
                 children: [ tag:      "__xmlstream__:node:cdata"
                             children: "Hello "
                           ]
                           [ tag:      em
                             children: [ tag:      "__xmlstream__:node:cdata"
                                         children: "there"
                                       ]
                           ]
               ]
               [ tag:      bar
                 children: [ tag:      "__xmlstream__:node:cdata"
                             children: "Howdy "
                           ]
                           [ tag:      ref
                           ]
               ]
               [ tag:      "__xmlstream__:node:cdata"
                 children: "do"
               ]
  ]

=head1 METHODS

  new()          - creates a new node.  If you specify tag, then the root
  new(tag)         tag is set.  If you specify data, then cdata is added
  new(tag,cdata)   to the node as well.  Returns the created node.

  get_tag() - returns the root tag of the node.

  set_tag(tag) - set the root tag of the node to tag.

  add_child(node)      - adds the specified node as a child to the current
  add_child(tag)         node, or creates a new node with the specified tag
  add_child(tag,cdata)   as the root node.  Returns the node added.

  remove_child(node) - removes the child node from the current node.
  
  remove_cdata() - removes all of the cdata children from the current node.

  add_cdata(string) - adds the string as cdata onto the current nodes
                      child list.

  get_cdata() - returns all of the cdata children concatenated together
                into one string.

  get_attrib(attrib) - returns the value of the attrib if it is valid,
                       or returns undef is attrib is not a real
                       attribute.

  put_attrib(hash) - for each key/value pair specified, create an
                     attribute in the node.

  remove_attrib(attrib) - remove the specified attribute from the node.

lib/XML/Stream/Node.pm  view on Meta::CPAN

    {
        return $_[0];
    }

    my $self = {};
    bless($self, $proto);

    my ($tag,$data) = @_;

    $self->set_tag($tag) if defined($tag);
    $self->add_cdata($data) if defined($data);
    $self->remove_raw_xml();

    return $self;
}


sub debug
{
    my $self = shift;
    my ($indent) = @_;

    $indent = "" unless defined($indent);

    if ($self->{TAG} eq "__xmlstream__:node:cdata")
    {
        print        $indent,"cdata(",join("",@{$self->{CHILDREN}}),")\n";
    }
    else
    {
        print        $indent,"packet($self):\n";
        print        $indent,"tag:     <$self->{TAG}\n";
        if (scalar(keys(%{$self->{ATTRIBS}})) > 0)
        {
            print      $indent,"attribs:\n";
            foreach my $key (sort {$a cmp $b} keys(%{$self->{ATTRIBS}}))
            {

lib/XML/Stream/Node.pm  view on Meta::CPAN

    {
        if ($child == $self->{CHILDREN}->[$index])
        {
            splice(@{$self->{CHILDREN}},$index,1);
            last;
        }
    }
}


sub add_cdata
{
    my $self = shift;
    my $child = XML::Stream::Node->new("__xmlstream__:node:cdata");
    foreach my $cdata (@_)
    {
        push(@{$child->{CHILDREN}},$cdata);
    }
    push(@{$self->{CHILDREN}},$child);
    return $child;
}


sub get_cdata
{
    my $self = shift;

    my $cdata = "";
    foreach my $child (@{$self->{CHILDREN}})
    {
        $cdata .= join("",$child->children())
            if ($child->get_tag() eq "__xmlstream__:node:cdata");
    }

    return $cdata;
} 


sub remove_cdata
{
    my $self = shift;

    my @remove = ();
    foreach my $index (0..$#{$self->{CHILDREN}})
    {
        if ($self->{CHILDREN}->[$index]->get_tag() eq "__xmlstream__:node:cdata")
        {

            unshift(@remove,$index);
        }
    }
    foreach my $index (@remove)
    {
        splice(@{$self->{CHILDREN}},$index,1);
    }
} 

lib/XML/Stream/Node.pm  view on Meta::CPAN

sub copy
{
    my $self = shift;

    my $new_node = XML::Stream::Node->new();
    $new_node->set_tag($self->get_tag());
    $new_node->put_attrib($self->attrib());

    foreach my $child ($self->children())
    {
        if ($child->get_tag() eq "__xmlstream__:node:cdata")
        {
            $new_node->add_cdata($child->children());
        }
        else
        {
            $new_node->add_child($child->copy());
        }
    }

    return $new_node;
}





##############################################################################
#
# _handle_element - handles the main tag elements sent from the server.
#                   On an open tag it creates a new XML::Parser::Node so
#                   that _handle_cdata and _handle_element can add data
#                   and tags to it later.
#
##############################################################################
sub _handle_element
{
    my $self;
    $self = $_[0] if (ref($_[0]) eq "XML::Stream::Parser");
    $self = shift unless (ref($_[0]) eq "XML::Stream::Parser");
    my ($sax, $tag, %att) = @_;
    my $sid = $sax->getSID();

lib/XML/Stream/Node.pm  view on Meta::CPAN

        $self->{SIDS}->{$sid}->{node}->[$#{$self->{SIDS}->{$sid}->{node}}]->
            add_child($node);
    }

    push(@{$self->{SIDS}->{$sid}->{node}},$node);
}


##############################################################################
#
# _handle_cdata - handles the CDATA that is encountered.  Also, in the
#                      spirit of XML::Parser::Node it combines any sequential
#                      CDATA into one tag.
#
##############################################################################
sub _handle_cdata
{
    my $self;
    $self = $_[0] if (ref($_[0]) eq "XML::Stream::Parser");
    $self = shift unless (ref($_[0]) eq "XML::Stream::Parser");
    my ($sax, $cdata) = @_;
    my $sid = $sax->getSID();

    $self->debug(2,"Node: _handle_cdata: sid($sid) sax($sax) cdata($cdata)");

    return if ($#{$self->{SIDS}->{$sid}->{node}} == -1);

    $self->debug(2,"Node: _handle_cdata: sax($sax) cdata($cdata)");

    $self->{SIDS}->{$sid}->{node}->[$#{$self->{SIDS}->{$sid}->{node}}]->
        add_cdata($cdata);
}


##############################################################################
#
# _handle_close - when we see a close tag we need to pop the last element
#                      from the list and push it onto the end of the previous
#                      element.  This is how we build our hierarchy.
#
##############################################################################

lib/XML/Stream/Node.pm  view on Meta::CPAN

        if ($type eq "single")
        {
            foreach my $child ($XMLTree->children())
            {
                if ($$XMLTree[1]->[$child] eq $tag)
                {
                    $XMLTree->remove_child($child);

                    my $newChild = $XMLTree->add_child($tag);
                    $newChild->put_attrib(%{$attribs});
                    $newChild->add_cdata($data) if ($data ne "");
                    return;
                }
            }
        }
        my $newChild = $XMLTree->add_child($tag);
        $newChild->put_attrib(%{$attribs});
        $newChild->add_cdata($data) if ($data ne "");
    }
    else
    {
        $XMLTree->put_attrib(%{$attribs});
        $XMLTree->add_cdata($data) if ($data ne "");
    }
}


##############################################################################
#
# GetXMLData - takes a host of arguments and returns various data structures
#              that match them.
#
#              type - "existence" - returns 1 or 0 if the tag exists in the

lib/XML/Stream/Node.pm  view on Meta::CPAN

                    return 1;
                }
                #-------------------------------------------------------------
                # Return the raw CDATA value without mark ups, or the value of
                # the requested attribute.
                #-------------------------------------------------------------
                if ($type eq "value")
                {
                    if ($attrib eq "")
                    {
                        my $str = $child->get_cdata();
                        return $str;
                    }
                    return $XMLTree->get_attrib($attrib)
                        if defined($XMLTree->get_attrib($attrib));
                }
                #-------------------------------------------------------------
                # Return an array of values that represent the raw CDATA without
                # mark up tags for the requested tags.
                #-------------------------------------------------------------
                if ($type eq "value array")
                {
                    if ($attrib eq "")
                    {
                        my $str = $child->get_cdata();
                        push(@array,$str);
                    }
                    else
                    {
                        push(@array, $XMLTree->get_attrib($attrib))
                        if defined($XMLTree->get_attrib($attrib));
                    }
                }
                #-------------------------------------------------------------
                # Return a pointer to a new XML::Parser::Tree object that has

lib/XML/Stream/Node.pm  view on Meta::CPAN

                if ($type eq "tree array")
                {
                    push(@array,$child);
                }
                #-------------------------------------------------------------
                # Return an array of pointers to XML::Parser::Tree objects
                # that have the requested tag as the root tags.
                #-------------------------------------------------------------
                if ($type eq "child array")
                {
                    push(@array,$child) if ($child->get_tag() ne "__xmlstream__:node:cdata");
                }
                #-------------------------------------------------------------
                # Return a count of the number of tags that match
                #-------------------------------------------------------------
                if ($type eq "count")
                {
                    $count++;
                }
                #-------------------------------------------------------------
                # Return the attribute hash that matches this tag

lib/XML/Stream/Node.pm  view on Meta::CPAN

        #---------------------------------------------------------------------

        #---------------------------------------------------------------------
        # Return the raw CDATA value without mark ups, or the value of the
        # requested attribute.
        #---------------------------------------------------------------------
        if ($type eq "value")
        {
            if ($attrib eq "")
            {
                my $str = $XMLTree->get_cdata();
                return $str;
            }
            return $XMLTree->get_attrib($attrib)
                if $XMLTree->get_attrib($attrib);
        }
        #---------------------------------------------------------------------
        # Return a pointer to a new XML::Parser::Tree object that has the
        # requested tag as the root tag.
        #---------------------------------------------------------------------
        if ($type eq "tree")

lib/XML/Stream/Node.pm  view on Meta::CPAN


    my @children = $node->children();
    if (($#children > -1) ||
        (defined($rawXML) && ($rawXML ne "")) ||
        (defined($node->get_raw_xml()) && ($node->get_raw_xml() ne ""))
       )
    {
        $str .= ">";
        foreach my $child (@children)
        {
            if ($child->get_tag() eq "__xmlstream__:node:cdata")
            {
                $str .= &XML::Stream::EscapeXML(join("",$child->children()));
            }
            else
            {
                $str .= &XML::Stream::Node::BuildXML($child);
            }
        }
        $str .= $node->get_raw_xml()
            if (defined($node->get_raw_xml()) &&

lib/XML/Stream/Node.pm  view on Meta::CPAN

#              Good for config files.
#
##############################################################################
sub XML2Config
{
    my ($XMLTree) = @_;

    my %hash;
    foreach my $tree (&XML::Stream::GetXMLData("tree array",$XMLTree,"*"))
    {
        if ($tree->get_tag() eq "__xmlstream__:node:cdata")
        {
            my $str = join("",$tree->children());
            return $str unless ($str =~ /^\s*$/);
        }
        else
        {
            if (&XML::Stream::GetXMLData("count",$XMLTree,$tree->get_tag()) > 1)
            {
                push(@{$hash{$tree->get_tag()}},&XML::Stream::XML2Config($tree));
            }

lib/XML/Stream/Parser.pm  view on Meta::CPAN

    $self->{DTD} = (exists($args{dtd}) ? lc($args{dtd}) : 0);

    my $weak = $self;
    weaken $weak;
    if ($self->{STYLE} eq "tree")
    {
        $self->{HANDLER}->{startDocument} = sub{ $weak->startDocument(@_); };
        $self->{HANDLER}->{endDocument} = sub{ $weak->endDocument(@_); };
        $self->{HANDLER}->{startElement} = sub{ &XML::Stream::Tree::_handle_element(@_); };
        $self->{HANDLER}->{endElement} = sub{ &XML::Stream::Tree::_handle_close(@_); };
        $self->{HANDLER}->{characters} = sub{ &XML::Stream::Tree::_handle_cdata(@_); };
    }
    elsif ($self->{STYLE} eq "node")
    {
        $self->{HANDLER}->{startDocument} = sub{ $weak->startDocument(@_); };
        $self->{HANDLER}->{endDocument} = sub{ $weak->endDocument(@_); };
        $self->{HANDLER}->{startElement} = sub{ &XML::Stream::Node::_handle_element(@_); };
        $self->{HANDLER}->{endElement} = sub{ &XML::Stream::Node::_handle_close(@_); };
        $self->{HANDLER}->{characters} = sub{ &XML::Stream::Node::_handle_cdata(@_); };
    }
    $self->setHandlers(%{$args{handlers}});

    $self->{XMLONHOLD} = "";

    return $self;
}


###########################################################################

lib/XML/Stream/Parser.pm  view on Meta::CPAN

            {
                $self->{DOC} = 0;
                $self->{PARSING} = 0;
                &{$self->{HANDLER}->{endDocument}}($self);
                return $self->returnData(0);
            }
            next;
        }

        my $estart = index($self->{XML},"<");
        my $cdatastart = index($self->{XML},"<![CDATA[");
        if (($estart == 0) && ($cdatastart != 0))
        {
            my $close = index($self->{XML},">");
            if ($close == -1)
            {
                $self->{PARSING} = 0;
                return $self->returnData(0);
            }
            my $empty = (substr($self->{XML},$close-1,1) eq "/");
            my $starttag = substr($self->{XML},1,$close-($empty ? 2 : 1));
            my $nextspace = index($starttag," ");

lib/XML/Stream/Parser.pm  view on Meta::CPAN

            else
            {
                $self->{CURR}++;
                $self->{CNAME}->[$self->{CURR}] = $name;
            }
    
            $self->{XML} = substr($self->{XML},$close+1,length($self->{XML})-$close-1);
            next;
        }

        if ($cdatastart == 0)
        {
            my $cdataclose = index($self->{XML},"]]>");
            if ($cdataclose == -1)
            {
                $self->{PARSING} = 0;
                return $self->returnData(0);
            }
            
            &{$self->{HANDLER}->{characters}}($self,substr($self->{XML},9,$cdataclose-9));
            
            $self->{XML} = substr($self->{XML},$cdataclose+3,length($self->{XML})-$cdataclose-3);
            next;
         }

        if ($estart == -1)
        {
            $self->{XMLONHOLD} = $self->{XML};
            $self->{XML} = "";
        }
        elsif (($cdatastart == -1) || ($cdatastart > $estart))
        {
            &{$self->{HANDLER}->{characters}}($self,$self->entityCheck(substr($self->{XML},0,$estart)));
            $self->{XML} = substr($self->{XML},$estart,length($self->{XML})-$estart);
        }
    }
}


sub attribution
{

lib/XML/Stream/Parser.pm  view on Meta::CPAN

        }
        push @NEW, \%att;
        push @{$self->{TREE}}, \@NEW;
    }
}


sub characters
{
    my $self = shift;
    my ($sax, $cdata) = @_;

    return unless ($self->{DOC} == 1);

    if ($self->{STYLE} eq "debug") 
    {
        my $str = $cdata;
        $str =~ s/\n/\#10\;/g;
        print "$self->{DEBUGHEADER} || $str\n";
    }
    else
    {
        return if ($#{$self->{TREE}} == -1);

        my $pos = $#{$self->{TREE}};

        if ($pos > 0 && $self->{TREE}[$pos - 1] eq "0")
        {
            $self->{TREE}[$pos - 1] .= $cdata;
        }
        else
        {
            push @{$self->{TREE}[$#{$self->{TREE}}]}, 0;
            push @{$self->{TREE}[$#{$self->{TREE}}]}, $cdata;
        }  
    }
}


sub endElement
{
    my $self = shift;
    my ($sax, $tag) = @_;

lib/XML/Stream/Parser/DTD.pm  view on Meta::CPAN

        splice(@{$$tree[1]},@{$$tree[1]},0,@newBranch);
    }
    else
    {
        splice(@{$$tree[1]},$location,0,@newBranch);
    }
    return $tree;
}


sub addcdata
{
    my $self = shift;
    my ($tag,$child,$tree) = @_;

#  print "addchild: tag($tag) child($child)\n";

    my @current;
    if (defined($tree))
    {
#    &Net::Jabber::printData("\$tree",$tree);

lib/XML/Stream/Tree.pm  view on Meta::CPAN

use warnings;
use vars qw( $VERSION $LOADED );

$VERSION = "1.24";
$LOADED = 1;

##############################################################################
#
# _handle_element - handles the main tag elements sent from the server.
#                   On an open tag it creates a new XML::Parser::Tree so
#                   that _handle_cdata and _handle_element can add data
#                   and tags to it later.
#
##############################################################################
sub _handle_element
{
    my $self;
    $self = $_[0] if (ref($_[0]) eq "XML::Stream::Parser");
    $self = shift unless (ref($_[0]) eq "XML::Stream::Parser");
    my ($sax, $tag, %att) = @_;
    my $sid = $sax->getSID();

lib/XML/Stream/Tree.pm  view on Meta::CPAN

    {
        push @{ $self->{SIDS}->{$sid}->{tree}[ $#{$self->{SIDS}->{$sid}->{tree}}]}, $tag;
    }
    push @NEW, \%att;
    push @{$self->{SIDS}->{$sid}->{tree}}, \@NEW;
}


##############################################################################
#
# _handle_cdata - handles the CDATA that is encountered.  Also, in the
#                      spirit of XML::Parser::Tree it combines any sequential
#                      CDATA into one tag.
#
##############################################################################
sub _handle_cdata
{
    my $self;
    $self = $_[0] if (ref($_[0]) eq "XML::Stream::Parser");
    $self = shift unless (ref($_[0]) eq "XML::Stream::Parser");
    my ($sax, $cdata) = @_;
    my $sid = $sax->getSID();

    $self->debug(2,"_handle_cdata: sid($sid) sax($sax) cdata($cdata)");

    return if ($#{$self->{SIDS}->{$sid}->{tree}} == -1);

    $self->debug(2,"_handle_cdata: sax($sax) cdata($cdata)");

    my $pos = $#{$self->{SIDS}->{$sid}->{tree}};
    $self->debug(2,"_handle_cdata: pos($pos)");

    if ($pos > 0 && $self->{SIDS}->{$sid}->{tree}[$pos - 1] eq "0")
    {
        $self->debug(2,"_handle_cdata: append cdata");
        $self->{SIDS}->{$sid}->{tree}[$pos - 1] .= $cdata;
    }
    else
    {
        $self->debug(2,"_handle_cdata: new cdata");
        push @{$self->{SIDS}->{$sid}->{tree}[$#{$self->{SIDS}->{$sid}->{tree}}]}, 0;
        push @{$self->{SIDS}->{$sid}->{tree}[$#{$self->{SIDS}->{$sid}->{tree}}]}, $cdata;
    }  
}


##############################################################################
#
# _handle_close - when we see a close tag we need to pop the last element
#                      from the list and push it onto the end of the previous
#                      element.  This is how we build our hierarchy.
#

lib/XML/Stream/Tree.pm  view on Meta::CPAN

    {
        if ($type eq "single")
        {
            my ($child);
            foreach $child (1..$#{$$XMLTree[1]})
            {
                if ($$XMLTree[1]->[$child] eq $tag)
                {
                    if ($data ne "")
                    {
                        #todo: add code to handle writing the cdata again and appending it.
                        $$XMLTree[1]->[$child+1]->[1] = 0;
                        $$XMLTree[1]->[$child+1]->[2] = $data;
                    }
                    foreach $key (keys(%{$attribs}))
                    {
                        $$XMLTree[1]->[$child+1]->[0]->{$key} = $$attribs{$key};
                    }
                    return;
                }
            }

t/buildxml.t  view on Meta::CPAN

$packets[10] = "<newfilter bar='2'><add>foo2</add><bingo/></newfilter>";
$packets[11] = "<newfilter bar='3'><div>foo3</div><bingo/></newfilter>";
$packets[12] = "<newfilter foo='1'><sub>foo4</sub><bingo/></newfilter>";
$packets[13] = "<newfilter foo='2'><add>foo5</add><bingo/></newfilter>";
$packets[14] = "<newfilter foo='3'><div>foo6</div><bingo/></newfilter>";
$packets[15] = "<startest>
        <foo test='1'/>
        <bar/>
        <bing test='2'/>
    <bingo/></startest>";
$packets[16] = "<cdata_test test='6'>This is cdata with &lt;tags/&gt; embedded &lt;in&gt;it&lt;/in&gt;.<bingo/></cdata_test>";

my $packetIndex;
foreach my $xmlType ("tree","node")
{
    my $stream = XML::Stream->new(style => $xmlType);
    ok( defined($stream), "new() - $xmlType" );
    isa_ok( $stream, "XML::Stream" );

    $packetIndex = 0;
    $stream->SetCallBacks(node => sub{ onPacket($xmlType, @_) });

t/cdata.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More tests => 11;

BEGIN { use_ok('XML::Stream', 'Node'); }

my $x = XML::Stream::Node->new;
isa_ok $x, 'XML::Stream::Node';
$x->set_tag("body");
$x->add_cdata("one");

is ($x->GetXML(), q[<body>one</body>], 'cdata');

my $y = $x->copy;
isa_ok $y, 'XML::Stream::Node';
isnt $x, $y, 'not the same';

is ($y->GetXML(), q[<body>one</body>], 'copy cdata');

$x->add_child("a","two")->put_attrib(href=>"http://www.google.com");
$x->add_cdata("three");

is ($x->GetXML(), q[<body>one<a href='http://www.google.com'>two</a>three</body>], 'cdata/element/cdata');

my $z = $x->copy;
isa_ok $z, 'XML::Stream::Node';
isnt $x, $z, 'not the same';
isnt $y, $z, 'not the same';

is ($z->GetXML(), q[<body>one<a href='http://www.google.com'>two</a>three</body>], 'copy cdata/element/cdata');

t/parse_node.t  view on Meta::CPAN


  if ($packet->get_attrib("test") eq "3") {
    if (($packet->children())[1]->get_tag() eq "bar") {
      $tests[3] = 1;
    }
  }
  if ($packet->get_attrib("test") eq "4") {
    $tests[4] = 0;
  }
  if ($packet->get_attrib("test") eq "5") {
    if (((($packet->children())[1]->children())[1]->children())[1]->get_cdata() eq "This is a test.") {
      $tests[5] = 1;
    }
  }
  if ($packet->get_attrib("test") eq "6") {
    if ($packet->get_cdata() eq "This is cdata with <tags/> embedded <in>it</in>.") {
      $tests[6] = 1;
    }
  }
}

my $node = XML::Stream::Node->new("test","<foo/>");

is ($node->GetXML(),  "<test>&lt;foo/&gt;</test>");

t/test.xml  view on Meta::CPAN

    <newfilter bar='2'><add>foo2</add></newfilter>
    <newfilter bar='3'><div>foo3</div></newfilter>
    <newfilter foo='1'><sub>foo4</sub></newfilter>
    <newfilter foo='2'><add>foo5</add></newfilter>
    <newfilter foo='3'><div>foo6</div></newfilter>
    <startest>
        <foo test='1'/>
        <bar/>
        <bing test='2'/>
    </startest>
    <cdata_test test='6'><![CDATA[This is cdata with <tags/> embedded <in>it</in>.]]></cdata_test>
</test_xml>



( run in 0.327 second using v1.01-cache-2.11-cpan-ec4f86ec37b )