view release on metacpan or search on metacpan
mark = p;
p += 2; /* skip ![ */
SKIP_WHITESPACES(p);
//mark = p;
if(strncmp(p, "CDATA", 5) == 0) {
char *cdata = NULL;
p+=5;
SKIP_WHITESPACES(p);
if(*p != '[') {
fprintf(stderr, "Unsupported entity type at \"... -->%15s\"", mark);
err = XML_PARSER_GENERIC_ERR;
mark = ++p;
p = strstr(mark, "]]>");
if(!p) {
/* XXX - TODO - This error condition must be handled asap */
}
cdata = (char *)calloc(1, p-mark+1);
if(!cdata) {
err = XML_MEMORY_ERR;
goto _parser_err;
}
strncpy(cdata, mark, p-mark);
err = XmlExtraNodeHandler(xml, cdata, XML_NODETYPE_CDATA);
free(cdata);
p+=3;
} else {
fprintf(stderr, "Unsupported entity type at \"... -->%15s\"", mark);
err = XML_PARSER_GENERIC_ERR;
goto _parser_err;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Filter/Moose.pm view on Meta::CPAN
predicate => 'has_text',
default => sub { '' },
handles => { append_text => 'append', },
);
has cdata => ( isa => 'Bool', is => 'rw', );
sub is_root { return shift->stack_length == 0 }
sub parent_element {
my ($self) = @_;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Element.pm view on Meta::CPAN
foreach my $e (%HTML::Tagset::emptyElement) {
$emptyElement{$e} = 1
if substr( $e, 0, 1 ) eq '~' and $HTML::Tagset::emptyElement{$e};
}
my $in_cdata = 0;
my $nillio = [];
#--------------------------------------------------------------------------
#Some basic overrides:
lib/XML/Element.pm view on Meta::CPAN
}
$name =~ s/--/--/g; # can't have double --'s in XML comments
return "<!-- $name -->";
}
if ( $name eq '~cdata' ) {
$in_cdata = 1;
return "<![CDATA[";
}
my $tag = "<$name";
my $val;
lib/XML/Element.pm view on Meta::CPAN
my ($self) = @_;
# and a third parameter to signal emptiness?
my $name = $self->{'_tag'};
if ( $name eq '~cdata' ) {
$in_cdata = 0;
return "]]>";
}
"</$_[0]->{'_tag'}>";
}
lib/XML/Element.pm view on Meta::CPAN
push( @xml, $node->endtag_XML() );
} # otherwise it will have been an <... /> tag.
}
}
else { # it's just text
_xml_escape($node) unless ($in_cdata);
push( @xml, $node );
}
1; # keep traversing
}
);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/TreePP/Editor.pm view on Meta::CPAN
$REF_NAME = "XML::TreePP::Editor"; # package name
use vars qw( $VERSION $DEBUG $TPPKEYS );
$VERSION = '0.13';
$DEBUG = 0;
$TPPKEYS = "force_array force_hash cdata_scalar_ref user_agent http_lite lwp_useragent base_class elem_class xml_deref first_out last_out indent xml_decl output_encoding utf8_flag attr_prefix text_node_key ignore_error use_ixhash";
}
=pod
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/TreePP/XMLPath.pm view on Meta::CPAN
use vars qw($REF_NAME);
$REF_NAME = "XML::TreePP::XMLPath"; # package name
use vars qw( $VERSION $TPPKEYS );
$VERSION = '0.72';
$TPPKEYS = "force_array force_hash cdata_scalar_ref user_agent http_lite lwp_useragent base_class elem_class xml_deref first_out last_out indent xml_decl output_encoding utf8_flag attr_prefix text_node_key ignore_error use_ixhash";
use vars qw($DEBUG $DEBUGMETHOD $DEBUGNODE $DEBUGPATH $DEBUGFILTER $DEBUGDUMP);
$DEBUG = 0;
$DEBUGMETHOD = 1;
$DEBUGNODE = 2;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/TreePP.pm view on Meta::CPAN
The default value is null, it means that context of the elements
will determine to make hash or to keep it scalar as a text node.
See also L</text_node_key> option below.
Note that the special wildcard name C<'*'> means all elements.
=head2 cdata_scalar_ref
This option allows you to convert a cdata section into a reference
for scalar on parsing an XML document.
$tpp->set( cdata_scalar_ref => 1 );
The default value is false, it means that each cdata section is converted into a scalar.
=head2 user_agent
This option allows you to specify a HTTP_USER_AGENT string which
is used by parsehttp() method.
lib/XML/TreePP.pm view on Meta::CPAN
$node->{attributes} = $attr if ref $attr;
}
push( @$flat, $node );
}
elsif ($typeCDATA) { ## CDATASection
if ( exists $self->{cdata_scalar_ref} && $self->{cdata_scalar_ref} ) {
push( @$flat, \$contCDATA ); # as reference for scalar
}
else {
push( @$flat, $contCDATA ); # as scalar like text node
}
lib/XML/TreePP.pm view on Meta::CPAN
}
while ( scalar @$source ) {
my $node = shift @$source;
if ( !ref $node || UNIVERSAL::isa( $node, "SCALAR" ) ) {
push( @$text, $node ); # cdata or text node
next;
}
my $name = $node->{tagName};
if ( $node->{endTag} ) {
last if ( $parent eq $name );
lib/XML/TreePP.pm view on Meta::CPAN
elsif ( ! scalar grep {ref $_} @$text ) {
# some text node splitted
$text = join( '', @$text );
}
else {
# some cdata node
my $join = join( '', map {ref $_ ? $$_ : $_} @$text );
$text = \$join;
}
if ( $haschild ) {
# some child nodes and also text node
lib/XML/TreePP.pm view on Meta::CPAN
elsif ( UNIVERSAL::isa( $val, 'ARRAY' ) ) {
my $child = $self->array_to_xml( $key, $val );
push( @$out, $child );
}
elsif ( UNIVERSAL::isa( $val, 'SCALAR' ) ) {
my $child = $self->scalaref_to_cdata( $key, $val );
push( @$out, $child );
}
else {
my $ref = ref $val;
$self->warn( "Unsupported reference type: $ref in $key" ) if $ref;
lib/XML/TreePP.pm view on Meta::CPAN
elsif ( UNIVERSAL::isa( $val, 'ARRAY' ) ) {
my $child = $self->array_to_xml( $name, $val );
push( @$out, $child );
}
elsif ( UNIVERSAL::isa( $val, 'SCALAR' ) ) {
my $child = $self->scalaref_to_cdata( $name, $val );
push( @$out, $child );
}
else {
my $ref = ref $val;
$self->warn( "Unsupported reference type: $ref in $name" ) if $ref;
lib/XML/TreePP.pm view on Meta::CPAN
my $text = join( '', @$out );
$text;
}
sub scalaref_to_cdata {
my $self = shift;
my $name = shift;
my $ref = shift;
my $data = defined $$ref ? $$ref : '';
$data =~ s#(]])(>)#$1]]><![CDATA[$2#g;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Trivial.pm view on Meta::CPAN
sub TIEHASH {
my ($class, $a, $nsstack) = @_;
#$a is arrayref like [name, atts, type1, data1, type2, data2, ...]
my @ea; my %eh;#elements
my @ta; #texts
my @ca; #cdatas
my @pa; my %ph;#process instructions
my @na; #notes
my $firstkey;
my $lastkey;
my %next;
lib/XML/Trivial.pm view on Meta::CPAN
(1 == @_ or not defined $index)
and return wantarray ? @{tied(%$self)->{ta}} : tied(%$self)->{ta};
return tied(%$self)->{ta}[$index];
}
sub ca { #cdata array
my ($self, $index) = @_;
(1 == @_ or not defined $index)
and return wantarray ? @{tied(%$self)->{ca}} : tied(%$self)->{ca};
return tied(%$self)->{ca}[$index];
}
lib/XML/Trivial.pm view on Meta::CPAN
=item ca()
B<c>data B<a>rray(ref). Returns array(ref) of CDATA sections.
print "all cdatas under <text>:\n";
foreach ($$xml{0}{sections}{text}->ca) {
print " cdata: ".$_."\n";
}
=item ca($index)
B<c>data B<a>rray. Returns $index'th CDATA section under element.
print "first cdata section under <text>: ".$$xml{0}{sections}{text}->ca(0)."\n";
=item ts()
B<t>ext B<s>erialized. Returns all textnodes, serialized into scalar string.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Twig.pm view on Meta::CPAN
Notation => \&_twig_notation,
XMLDecl => \&_twig_xmldecl,
Doctype => \&_twig_doctype,
Element => \&_twig_element,
Attlist => \&_twig_attlist,
CdataStart => \&_twig_cdatastart,
CdataEnd => \&_twig_cdataend,
Proc => \&_twig_pi,
Comment => \&_twig_comment,
Default => \&_twig_default,
ExternEnt => \&_twig_extern_ent,
);
lib/XML/Twig.pm view on Meta::CPAN
}
else
{ $self->set_output_filter( 0); }
if( $args{RemoveCdata})
{ $self->set_remove_cdata( $args{RemoveCdata});
delete $args{RemoveCdata};
}
else
{ $self->set_remove_cdata( 0); }
if( $args{OutputTextFilter})
{ $self->set_output_text_filter( $args{OutputTextFilter});
delete $args{OutputTextFilter};
}
lib/XML/Twig.pm view on Meta::CPAN
}
}
}
# some versions of HTML::TreeBuilder escape CDATA sections
$$xml=~ s{(<!\[CDATA\[.*?\]\]>)}{_unescape_cdata( $1)}eg;
}
sub _xml_parser_encodings
{ my @encodings=( 'iso-8859-1'); # this one is included by default, there is no map for it in @INC
foreach my $inc (@INC)
{ push @encodings, map { basename( $_, '.enc') } glob( File::Spec->catdir( $inc => XML => Parser => Encodings => '*.enc')); }
return map { $_ => 1 } @encodings;
}
}
sub _unescape_cdata
{ my( $cdata)= @_;
$cdata=~s{<}{<}g;
$cdata=~s{>}{>}g;
$cdata=~s{&}{&}g;
return $cdata;
}
sub _as_XML {
# fork of HTML::Element::as_XML, which is a little too buggy and inconsistent between versions for my liking
lib/XML/Twig.pm view on Meta::CPAN
{ my $t= shift;
$t->{twig_parsing}= 0;
delete $t->{twig_current};
delete $t->{extra_data};
delete $t->{twig_dtd};
delete $t->{twig_in_pcdata};
delete $t->{twig_in_cdata};
delete $t->{twig_stored_space};
delete $t->{twig_entity_list};
$t->root->delete if( $t->root);
delete $t->{twig_root};
return $t;
lib/XML/Twig.pm view on Meta::CPAN
if( ! $t->{twig_discard_all_spaces})
{ if( ! defined( $t->{twig_space_policy}->{$current_gi}))
{ $t->{twig_space_policy}->{$current_gi}= _space_policy( $t, $current_gi); }
if( $t->{twig_space_policy}->{$current_gi} || ($t->{twig_stored_spaces}!~ m{\n}) || $t->{twig_preserve_space})
{ _insert_pcdata( $t, $t->{twig_stored_spaces} ); }
}
$t->{twig_stored_spaces}='';
return;
lib/XML/Twig.pm view on Meta::CPAN
#foreach my $s (@_) { next if ref $s; warn "$s: ", is_utf8( $s) ? "has flag" : "FLAG NOT SET"; } # YYY
my ($p, $gi, @att)= @_;
my $t=$p->{twig};
# empty the stored pcdata (space stored in case they are really part of
# a pcdata element) or stored it if the space policy dictates so
# create a pcdata element with the spaces if need be
_add_or_discard_stored_spaces( $t);
my $parent= $t->{twig_current};
# if we were parsing PCDATA then we exit the pcdata
if( $t->{twig_in_pcdata})
{ $t->{twig_in_pcdata}= 0;
$t->_trigger_text_handler();
$parent->del_twig_current;
$parent= $parent->_parent;
}
lib/XML/Twig.pm view on Meta::CPAN
{ # warn " in _twig_end...\n"; # DEBUG handler
my ($p, $gi) = @_;
my $t=$p->{twig};
if( $t->{twig_in_pcdata} )
{ $t->_trigger_text_handler(); }
if( $t->{twig_map_xmlns}) { $gi= $t->_replace_prefix( $gi); }
_add_or_discard_stored_spaces( $t);
# the new twig_current is the parent
my $elt= $t->{twig_current};
$elt->del_twig_current;
# if we were parsing PCDATA then we exit the pcdata too
if( $t->{twig_in_pcdata})
{
$t->{twig_in_pcdata}= 0;
$elt= $elt->_parent if($elt->_parent);
$elt->del_twig_current;
}
# parent is the new current element
lib/XML/Twig.pm view on Meta::CPAN
my ($p, $string)= @_;
my $t=$p->{twig};
if( $t->{twig_keep_encoding})
{ if( !$t->{twig_in_cdata})
{ $string= $p->original_string(); }
else
{
use bytes;
if( length( $string) < 1024)
lib/XML/Twig.pm view on Meta::CPAN
if( $t->{twig_input_filter}) { $string= $t->{twig_input_filter}->( $string); }
if( $t->{twig_char_handler}) { $string= $t->{twig_char_handler}->( $string); }
my $elt= $t->{twig_current};
if( $t->{twig_in_cdata})
{ # text is the continuation of a previously created cdata
$elt->append_cdata( $t->{twig_stored_spaces} . $string);
}
elsif( $t->{twig_in_pcdata})
{ # text is the continuation of a previously created pcdata
if( $t->{extra_data})
{ $elt->_push_extra_data_in_pcdata( $t->{extra_data}, length( $elt->{pcdata}));
$t->{extra_data}='';
}
$elt->append_pcdata( $string);
}
else
{
# text is just space, which might be discarded later
if( $string=~/\A\s*\Z/s)
lib/XML/Twig.pm view on Meta::CPAN
{ # no extra data, just store the spaces
$t->{twig_stored_spaces}.= $string;
}
}
else
{ my $new_elt= _insert_pcdata( $t, $t->{twig_stored_spaces}.$string);
$elt->del_twig_current;
$new_elt->set_twig_current;
$t->{twig_current}= $new_elt;
$t->{twig_in_pcdata}=1;
if( $t->{extra_data})
{ $new_elt->_push_extra_data_in_pcdata( $t->{extra_data}, 0);
$t->{extra_data}='';
}
}
}
return;
}
sub _twig_cdatastart
{ # warn " in _twig_cdatastart...\n"; # DEBUG handler
my $p= shift;
my $t=$p->{twig};
$t->{twig_in_cdata}=1;
my $cdata= $t->{twig_elt_class}->new( $CDATA);
my $twig_current= $t->{twig_current};
if( $t->{twig_in_pcdata})
{ # create the node as a sibling of the PCDATA
$cdata->set_prev_sibling( $twig_current);
$twig_current->set_next_sibling( $cdata);
my $parent= $twig_current->_parent;
$cdata->set_parent( $parent);
$parent->set_last_child( $cdata);
$t->{twig_in_pcdata}=0;
}
else
{ # we have to create a PCDATA element if we need to store spaces
if( $t->_space_policy($twig_current->gi) && $t->{twig_stored_spaces})
{ _insert_pcdata( $t, $t->{twig_stored_spaces}); }
$t->{twig_stored_spaces}='';
# create the node as a child of the current element
$cdata->set_parent( $twig_current);
if( my $prev_sibling= $twig_current->_last_child)
{ $cdata->set_prev_sibling( $prev_sibling);
$prev_sibling->set_next_sibling( $cdata);
}
else
{ $twig_current->set_first_child( $cdata); }
$twig_current->set_last_child( $cdata);
}
$twig_current->del_twig_current;
$t->{twig_current}= $cdata;
$cdata->set_twig_current;
if( $t->{extra_data}) { $cdata->set_extra_data( $t->{extra_data}); $t->{extra_data}='' };
return;
}
sub _twig_cdataend
{ # warn " in _twig_cdataend...\n"; # DEBUG handler
my $p= shift;
my $t=$p->{twig};
$t->{twig_in_cdata}=0;
my $elt= $t->{twig_current};
$elt->del_twig_current;
my $cdata= $elt->cdata;
$elt->_set_cdata( $cdata);
push @{$t->{_twig_context_stack}}, { $ST_TAG => $CDATA };
if( $t->{twig_handlers})
{ # look for handlers
lib/XML/Twig.pm view on Meta::CPAN
$elt= $elt->_parent;
$t->{twig_current}= $elt;
$elt->set_twig_current;
$t->{twig_long_cdata}=0;
return;
}
sub _pi_elt_handlers
{ my( $t, $pi)= @_;
lib/XML/Twig.pm view on Meta::CPAN
}
if( ! $t->root)
{ $t->_add_cpi_outside_of_root( leading_cpi => $elt);
}
elsif( $t->{twig_in_pcdata})
{ $t->_trigger_text_handler();
# create the node as a sibling of the PCDATA
$elt->paste_after( $twig_current);
$t->{twig_in_pcdata}=0;
}
elsif( $twig_current)
{ # we have to create a PCDATA element if we need to store spaces
if( $t->_space_policy($twig_current->gi) && $t->{twig_stored_spaces})
{ _insert_pcdata( $t, $t->{twig_stored_spaces}); }
$t->{twig_stored_spaces}='';
# create the node as a child of the current element
$elt->paste_last_child( $twig_current);
}
else
lib/XML/Twig.pm view on Meta::CPAN
@{$t}{ qw( twig_parser twig_parsing _twig_context_stack twig_current) }=();
return $t;
}
sub _insert_pcdata
{ my( $t, $string)= @_;
# create a new PCDATA element
my $parent= $t->{twig_current}; # always defined
my $elt;
if( exists $t->{twig_alt_elt_class})
{ $elt= $t->{twig_elt_class}->new( $PCDATA);
$elt->_set_pcdata( $string);
}
else
{ $elt= bless( { gi => $XML::Twig::gi2index{$PCDATA}, pcdata => $string }, 'XML::Twig::Elt'); }
my $prev_sibling= $parent->_last_child;
if( $prev_sibling)
{ $prev_sibling->set_next_sibling( $elt);
$elt->set_prev_sibling( $prev_sibling);
lib/XML/Twig.pm view on Meta::CPAN
# after the closing tag (no twig_current and root has been created)
if( ! $t->{twig_current} && $t->{twig_root} && $string=~ m{^\s+$}m) { $t->{twig_stored_spaces} .= $string; }
# process only if we have an entity
if( $string=~ m{^&([^;]*);$})
{ # the entity has to be pure pcdata, or we have a problem
if( ($p->original_string=~ m{^<}) && ($p->original_string=~ m{>$}) )
{ # string is a tag, entity is in an attribute
$t->{twig_entities_in_attribute}=1 if( $t->{twig_do_not_escape_amp_in_atts});
}
else
lib/XML/Twig.pm view on Meta::CPAN
my $ent= $t->{twig_elt_class}->new( $ENT);
$ent->set_ent( $string);
_add_or_discard_stored_spaces( $t);
if( $t->{twig_in_pcdata})
{ # create the node as a sibling of the #PCDATA
$ent->set_prev_sibling( $twig_current);
$twig_current->set_next_sibling( $ent);
my $parent= $twig_current->_parent;
$ent->set_parent( $parent);
$parent->set_last_child( $ent);
# the twig_current is now the parent
$twig_current->del_twig_current;
$t->{twig_current}= $parent;
# we left pcdata
$t->{twig_in_pcdata}=0;
}
else
{ # create the node as a child of the current element
$ent->set_parent( $twig_current);
if( my $prev_sibling= $twig_current->_last_child)
lib/XML/Twig.pm view on Meta::CPAN
else
{ $p->setHandlers( %twig_handlers_finish_print_original); }
return $t;
}
sub set_remove_cdata { return XML::Twig::Elt::set_remove_cdata( @_); }
sub output_filter { return XML::Twig::Elt::output_filter( @_); }
sub set_output_filter { return XML::Twig::Elt::set_output_filter( @_); }
sub output_text_filter { return XML::Twig::Elt::output_text_filter( @_); }
lib/XML/Twig.pm view on Meta::CPAN
my $atts= ref $_[0] eq 'HASH' ? shift : undef;
if( $atts && defined $atts->{$CDATA})
{ delete $atts->{$CDATA};
my $cdata= $class->new( $CDATA => @_);
return $class->new( $gi, $atts, $cdata);
}
if( $gi eq $PCDATA)
{ if( grep { ref $_ } @_) { croak "element $PCDATA can only be created from text"; }
$elt->_set_pcdata( join '', @_);
}
elsif( $gi eq $ENT)
{ $elt->set_ent( shift); }
elsif( $gi eq $CDATA)
{ if( grep { ref $_ } @_) { croak "element $CDATA can only be created from text"; }
$elt->_set_cdata( join '', @_);
}
elsif( $gi eq $COMMENT)
{ if( grep { ref $_ } @_) { croak "element $COMMENT can only be created from text"; }
$elt->_set_comment( join '', @_);
}
lib/XML/Twig.pm view on Meta::CPAN
return $elt;
}
# optimized version of $elt->new( PCDATA, $text);
sub _new_pcdata
{ my $class= $_[0];
$class= ref $class || $class;
my $elt = {};
bless $elt, $class;
$elt->set_gi( $PCDATA);
$elt->_set_pcdata( $_[1]);
return $elt;
}
# this function creates an XM:::Twig::Elt from a string
# it is quite clumsy at the moment, as it just creates a
lib/XML/Twig.pm view on Meta::CPAN
{ return $_[0]->gi; }
else
{ return 0; }
}
sub is_pcdata
{ my $elt= shift;
return (exists $elt->{'pcdata'});
}
sub is_cdata
{ my $elt= shift;
return (exists $elt->{'cdata'});
}
sub is_pi
{ my $elt= shift;
return (exists $elt->{'target'});
lib/XML/Twig.pm view on Meta::CPAN
return (exists $elt->{ent} || $elt->{ent_name});
}
sub is_text
{ my $elt= shift;
return (exists( $elt->{'pcdata'}) || (exists $elt->{'cdata'}));
}
sub is_empty
{ return $_[0]->{empty} || 0; }
lib/XML/Twig.pm view on Meta::CPAN
sub set_asis
{ my $elt=shift;
foreach my $descendant ($elt, $elt->_descendants )
{ $descendant->{asis}= 1;
if( $descendant->is_cdata)
{ $descendant->set_gi( $PCDATA);
$descendant->_set_pcdata( $descendant->cdata);
}
}
return $elt;
}
lib/XML/Twig.pm view on Meta::CPAN
my $curr_elt= $t->{twig_current};
return 1 unless( $curr_elt);
return $curr_elt->in( $elt);
}
sub set_pcdata
{ my( $elt, $pcdata)= @_;
if( $elt->_extra_data_in_pcdata)
{ _try_moving_extra_data( $elt, $pcdata);
}
$elt->{pcdata}= $pcdata;
return $elt;
}
sub _extra_data_in_pcdata { return $_[0]->{extra_data_in_pcdata}; }
sub _set_extra_data_in_pcdata { $_[0]->{extra_data_in_pcdata}= $_[1]; return $_[0]; }
sub _del_extra_data_in_pcdata { delete $_[0]->{extra_data_in_pcdata}; return $_[0]; }
sub _unshift_extra_data_in_pcdata
{ my $e= shift;
$e->{extra_data_in_pcdata}||=[];
unshift @{$e->{extra_data_in_pcdata}}, { text => shift(), offset => shift() };
}
sub _push_extra_data_in_pcdata
{ my $e= shift;
$e->{extra_data_in_pcdata}||=[];
push @{$e->{extra_data_in_pcdata}}, { text => shift(), offset => shift() };
}
sub _extra_data_before_end_tag { return $_[0]->{extra_data_before_end_tag} || ''; }
sub _set_extra_data_before_end_tag { $_[0]->{extra_data_before_end_tag}= $_[1]; return $_[0]}
sub _del_extra_data_before_end_tag { delete $_[0]->{extra_data_before_end_tag}; return $_[0]}
lib/XML/Twig.pm view on Meta::CPAN
{ $elt->{extra_data_before_end_tag}= $data; }
return $elt;
}
# internal, in cases where we know there is no extra_data (inlined anyway!)
sub _set_pcdata { $_[0]->{pcdata}= $_[1]; }
# try to figure out if we can keep the extra_data around
sub _try_moving_extra_data
{ my( $elt, $modified)=@_;
my $initial= $elt->{pcdata};
my $cpis= $elt->_extra_data_in_pcdata;
if( (my $offset= index( $modified, $initial)) != -1)
{ # text has been added
foreach (@$cpis) { $_->{offset}+= $offset; }
}
elsif( ($offset= index( $initial, $modified)) != -1)
{ # text has been cut
my $len= length( $modified);
foreach my $cpi (@$cpis) { $cpi->{offset} -= $offset; }
$elt->_set_extra_data_in_pcdata( [ grep { $_->{offset} >= 0 && $_->{offset} < $len } @$cpis ]);
}
else
{ _match_extra_data_words( $elt, $initial, $modified)
|| _match_extra_data_chars( $elt, $initial, $modified)
|| $elt->_del_extra_data_in_pcdata;
}
}
sub _match_extra_data_words
{ my( $elt, $initial, $modified)= @_;
lib/XML/Twig.pm view on Meta::CPAN
}
sub _match_extra_data
{ my( $elt, $length, $initial, $modified)= @_;
my $cpis= $elt->_extra_data_in_pcdata;
if( @$initial <= @$modified)
{
my( $ok, $positions, $offsets)= _pos_offset( $initial, $modified);
if( $ok)
lib/XML/Twig.pm view on Meta::CPAN
$pos= shift @$positions || $length +1;
}
$cpi->{offset} -= $offset;
if( $cpi->{offset} < $prev_pos) { delete $cpi->{text}; }
}
$elt->_set_extra_data_in_pcdata( [ grep { exists $_->{text} } @$cpis ]);
return 1;
}
}
return 0;
}
lib/XML/Twig.pm view on Meta::CPAN
$l_length += $length;
}
return( 1, \@pos, \@offset);
}
sub append_pcdata
{ $_[0]->{'pcdata'}.= $_[1];
return $_[0];
}
sub pcdata { return $_[0]->{pcdata}; }
sub append_extra_data
{ $_[0]->{extra_data}.= $_[1];
return $_[0];
}
lib/XML/Twig.pm view on Meta::CPAN
sub set_ent { $_[0]->{ent}= $_[1]; return $_[0]; }
sub ent { return $_[0]->{ent}; }
sub ent_name { return substr( $_[0]->ent, 1, -1);}
sub set_cdata
{ my $elt= shift;
unless( $elt->{gi} == $XML::Twig::gi2index{$CDATA})
{ $elt->cut_children;
$elt->insert_new_elt( first_child => $CDATA, @_);
return $elt;
}
$elt->_set_cdata( $_[0]);
return $_[0];
}
sub _set_cdata
{ $_[0]->{cdata}= $_[1];
return $_[0];
}
sub append_cdata
{ $_[0]->{cdata}.= $_[1];
return $_[0];
}
sub cdata { return $_[0]->{cdata}; }
sub contains_only_text
{ my $elt= shift;
return 0 unless $elt->is_elt;
foreach my $child ($elt->_children)
lib/XML/Twig.pm view on Meta::CPAN
if( $target)
{
if( $target->is( $ELT))
{ $target->set_extra_data( $extra_data . ($target->extra_data || '')); }
elsif( $target->is( $TEXT))
{ $target->_unshift_extra_data_in_pcdata( $extra_data, 0); } # TO CHECK
}
else
{ my $parent= $elt->parent; # always exists or the erase cannot be performed
$parent->_prefix_extra_data_before_end_tag( $extra_data);
}
lib/XML/Twig.pm view on Meta::CPAN
{ if( my $target= $elt->_next_sibling)
{ if( $target->is( $ELT))
{ $target->set_extra_data( $extra_data . ($target->extra_data || '')); }
elsif( $target->is( $TEXT))
{
$target->_unshift_extra_data_in_pcdata( $extra_data, 0);
}
}
elsif( my $parent= $elt->parent)
{ $parent->_prefix_extra_data_before_end_tag( $extra_data); }
}
lib/XML/Twig.pm view on Meta::CPAN
{ my( $elt, $offset)= @_;
my $text_elt= $elt->is_text ? $elt : $elt->first_child( $TEXT) || return '';
my $string= $text_elt->text;
my $left_string= substr( $string, 0, $offset);
my $right_string= substr( $string, $offset);
$text_elt->set_pcdata( $left_string);
my $new_elt= $elt->new( $elt->gi, $right_string);
$new_elt->paste( after => $elt);
return $new_elt;
}
lib/XML/Twig.pm view on Meta::CPAN
my $t1_length= length( $e1->text);
$e1->set_text( $e1->text . $e2->text);
if( my $extra_data_in_pcdata= $e2->_extra_data_in_pcdata)
{ foreach my $data (@$extra_data_in_pcdata) { $e1->_push_extra_data_in_pcdata( $data->{text}, $data->{offset} + $t1_length); } }
$e2->delete;
return $e1;
}
sub merge
{ my( $e1, $e2)= @_;
my @e2_children= $e2->_children;
if( $e1->_last_child && $e1->_last_child->is_pcdata
&& @e2_children && $e2_children[0]->is_pcdata
)
{ my $t1_length= length( $e1->_last_child->{pcdata});
my $child1= $e1->_last_child;
my $child2= shift @e2_children;
$child1->{pcdata} .= $child2->{pcdata};
my $extra_data= $e1->_extra_data_before_end_tag . $e2->extra_data;
if( $extra_data)
{ $e1->_del_extra_data_before_end_tag;
$child1->_push_extra_data_in_pcdata( $extra_data, $t1_length);
}
if( my $extra_data_in_pcdata= $child2->_extra_data_in_pcdata)
{ foreach my $data (@$extra_data_in_pcdata) { $child1->_push_extra_data_in_pcdata( $data->{text}, $data->{offset} + $t1_length); } }
if( my $extra_data_before_end_tag= $e2->_extra_data_before_end_tag)
{ $e1->_set_extra_data_before_end_tag( $extra_data_before_end_tag); }
}
lib/XML/Twig.pm view on Meta::CPAN
if( $elt->extra_data) { $copy->set_extra_data( $elt->extra_data); }
if( $elt->_extra_data_before_end_tag) { $copy->_set_extra_data_before_end_tag( $elt->_extra_data_before_end_tag); }
if( $elt->is_asis) { $copy->set_asis; }
if( $elt->is_pcdata)
{ $copy->set_pcdata( $elt->pcdata);
if( $elt->_extra_data_in_pcdata) { $copy->_set_extra_data_in_pcdata( $elt->_extra_data_in_pcdata); }
}
elsif( $elt->is_cdata)
{ $copy->_set_cdata( $elt->cdata);
if( $elt->_extra_data_in_pcdata) { $copy->_set_extra_data_in_pcdata( $elt->_extra_data_in_pcdata); }
}
elsif( $elt->is_pi)
{ $copy->_set_pi( $elt->target, $elt->data); }
elsif( $elt->is_comment)
{ $copy->_set_comment( $elt->comment); }
lib/XML/Twig.pm view on Meta::CPAN
BEGIN {
my $pretty = 0;
my $quote = '"';
my $INDENT = ' ';
my $empty_tag_style = 0;
my $remove_cdata = 0;
my $keep_encoding = 0;
my $expand_external_entities = 0;
my $keep_atts_order = 0;
my $do_not_escape_amp_in_atts = 0;
my $WRAP = '80';
lib/XML/Twig.pm view on Meta::CPAN
);
my $xml_space_preserve; # set when an element includes xml:space="preserve"
my $output_filter; # filters the entire output (including < and >)
my $output_text_filter; # filters only the text part (tag names, attributes, pcdata)
my $replaced_ents= $REPLACED_ENTS;
# returns those pesky "global" variables so you can switch between twigs
sub global_state ## no critic (Subroutines::ProhibitNestedSubs);
{ return
{ pretty => $pretty,
quote => $quote,
indent => $INDENT,
empty_tag_style => $empty_tag_style,
remove_cdata => $remove_cdata,
keep_encoding => $keep_encoding,
expand_external_entities => $expand_external_entities,
output_filter => $output_filter,
output_text_filter => $output_text_filter,
keep_atts_order => $keep_atts_order,
lib/XML/Twig.pm view on Meta::CPAN
{ my $state= shift;
$pretty = $state->{pretty};
$quote = $state->{quote};
$INDENT = $state->{indent};
$empty_tag_style = $state->{empty_tag_style};
$remove_cdata = $state->{remove_cdata};
$keep_encoding = $state->{keep_encoding};
$expand_external_entities = $state->{expand_external_entities};
$output_filter = $state->{output_filter};
$output_text_filter = $state->{output_text_filter};
$keep_atts_order = $state->{keep_atts_order};
lib/XML/Twig.pm view on Meta::CPAN
{ set_global_state(
{ pretty => 0,
quote => '"',
indent => $INDENT,
empty_tag_style => 0,
remove_cdata => 0,
keep_encoding => 0,
expand_external_entities => 0,
output_filter => undef,
output_text_filter => undef,
keep_atts_order => undef,
lib/XML/Twig.pm view on Meta::CPAN
croak "invalid quote '$style'" unless( exists $quote_style{$style});
$quote= $quote_style{$style};
return $old_quote;
}
sub set_remove_cdata
{ my $new_value= defined $_[1] ? $_[1] : $_[0];
my $old_value= $remove_cdata;
$remove_cdata= $new_value;
return $old_value;
}
sub set_indent
{ my $new_value= defined $_[1] ? $_[1] : $_[0];
lib/XML/Twig.pm view on Meta::CPAN
# used for pretty printing
if( my $parent= $elt->parent) { $parent->{has_flushed_child}= 1; }
}
else # text or special element
{ my $text;
if( $elt->is_pcdata) { $text= $elt->pcdata_xml_string;
if( my $parent= $elt->parent)
{ $parent->{contains_text}= 1; }
}
elsif( $elt->is_cdata) { $text= $elt->cdata_string;
if( my $parent= $elt->parent)
{ $parent->{contains_text}= 1; }
}
elsif( $elt->is_pi) { $text= $elt->pi_string; }
elsif( $elt->is_comment) { $text= $elt->comment_string; }
lib/XML/Twig.pm view on Meta::CPAN
my $child= $elt->_first_child || '';
while( $child)
{ $string.= $child->xml_text;
} continue { $child= $child->_next_sibling; }
}
elsif( $elt->is_pcdata) { $string .= $output_filter ? $output_filter->($elt->pcdata_xml_string)
: $elt->pcdata_xml_string;
}
elsif( $elt->is_cdata) { $string .= $output_filter ? $output_filter->($elt->cdata_string)
: $elt->cdata_string;
}
elsif( $elt->is_ent) { $string .= $elt->ent_string; }
return $string;
}
lib/XML/Twig.pm view on Meta::CPAN
push @sprint, $elt->end_tag unless( $no_tag);
$xml_space_preserve-- if $preserve;
}
else
{ push @sprint, $elt->{extra_data} if( $elt->{extra_data}) ;
if( $elt->is_pcdata) { push @sprint, $elt->pcdata_xml_string; }
elsif( $elt->is_cdata) { push @sprint, $elt->cdata_string; }
elsif( $elt->is_pi) { if( ($pretty >= $INDENTED) && !$elt->parent->{contains_text}) { push @sprint, "\n" . $INDENT x $elt->level; }
push @sprint, $elt->pi_string;
}
elsif( $elt->is_comment) { if( ($pretty >= $INDENTED) && !$elt->parent->{contains_text}) { push @sprint, "\n" . $INDENT x $elt->level; }
push @sprint, $elt->comment_string;
lib/XML/Twig.pm view on Meta::CPAN
sub xml_string
{ my $elt= shift;
isa( $_[0], 'HASH') ? $elt->sprint( shift(), 1) : $elt->sprint( 1);
}
sub pcdata_xml_string
{ my $elt= shift;
if( defined( my $string= $elt->{pcdata}) )
{
if( ! $elt->_extra_data_in_pcdata)
{
$string=~ s/([$replaced_ents])/$XML::Twig::base_ent{$1}/g unless( !$replaced_ents || $keep_encoding || $elt->{asis});
$string=~ s{\Q]]>}{]]>}g;
}
else
{ _gen_mark( $string); # used by _(un)?protect_extra_data
foreach my $data (reverse @{$elt->_extra_data_in_pcdata})
{ my $substr= substr( $string, $data->{offset});
if( $keep_encoding || $elt->{asis})
{ substr( $string, $data->{offset}, 0, $data->{text}); }
else
{ substr( $string, $data->{offset}, 0, _protect_extra_data( $data->{text})); }
lib/XML/Twig.pm view on Meta::CPAN
sub _unprotect_extra_data
{ $_[0]=~ s{:$mark:(\w+):}{$ent2char{$1}}g; }
}
sub cdata_string
{ my $cdata= $_[0]->cdata;
unless( defined $cdata) { return ''; }
if( $remove_cdata)
{ $cdata=~ s/([$replaced_ents])/$XML::Twig::base_ent{$1}/g; }
else
{ # if the CDATA includes the end of CDATA marker, we need to split it
$cdata=~ s{$CDATA_END}{]]$CDATA_END$CDATA_START>}g;
$cdata= $CDATA_START . $cdata . $CDATA_END;
}
return $cdata;
}
sub att_xml_string
{ my $elt= shift;
my $att= shift;
lib/XML/Twig.pm view on Meta::CPAN
if( @options && grep { lc( $_) eq 'no_recurse' } @options) { return $elt->text_only; }
my $sep = (@options && grep { lc( $_) eq 'sep' } @options) ? ' ' : '';
my $string;
if( $elt->is_pcdata) { return $elt->pcdata . $sep; }
elsif( $elt->is_cdata) { return $elt->cdata . $sep; }
elsif( $elt->is_pi) { return $elt->pi_string . $sep; }
elsif( $elt->is_comment) { return $elt->comment . $sep; }
elsif( $elt->is_ent) { return $elt->ent . $sep ; }
my $child= $elt->_first_child ||'';
lib/XML/Twig.pm view on Meta::CPAN
return $text;
}
sub trim
{ my( $elt)= @_;
my $pcdata= $elt->first_descendant( $TEXT);
(my $pcdata_text= $pcdata->text)=~ s{^\s+}{}s;
$pcdata->set_text( $pcdata_text);
$pcdata= $elt->last_descendant( $TEXT);
($pcdata_text= $pcdata->text)=~ s{\s+$}{};
$pcdata->set_text( $pcdata_text);
foreach my $pcdata ($elt->descendants( $TEXT))
{ ($pcdata_text= $pcdata->text)=~ s{\s+}{ }g;
$pcdata->set_text( $pcdata_text);
}
return $elt;
}
# remove cdata sections (turns them into regular pcdata) in an element
sub remove_cdata
{ my $elt= shift;
foreach my $cdata ($elt->descendants_or_self( $CDATA))
{ if( $keep_encoding)
{ my $data= $cdata->cdata;
$data=~ s{([&<"'])}{$XML::Twig::base_ent{$1}}g;
$cdata->set_pcdata( $data);
}
else
{ $cdata->set_pcdata( $cdata->cdata); }
$cdata->set_gi( $PCDATA);
undef $cdata->{cdata};
}
}
sub _is_private { return _is_private_name( $_[0]->gi); }
sub _is_private_name { return $_[0]=~ m{^#(?!default:)}; }
lib/XML/Twig.pm view on Meta::CPAN
# merges consecutive #PCDATAs in am element
sub normalize
{ my( $elt)= @_;
my @descendants= $elt->descendants( $PCDATA);
while( my $desc= shift @descendants)
{ if( ! length $desc->{pcdata}) { $desc->delete; next; }
while( @descendants && $desc->_next_sibling && $desc->_next_sibling== $descendants[0])
{ my $to_merge= shift @descendants;
$desc->merge_text( $to_merge);
}
}
lib/XML/Twig.pm view on Meta::CPAN
if( (my $data= $end_tag_data->( $elt)) && (my $end_element = $handler->can( 'end_element')) )
{ $end_element->( $handler, $data); }
_end_prefix_mapping( $elt, $handler);
}
else # text or special element
{ if( $elt->is_pcdata && (my $characters= $handler->can( 'characters')))
{ $characters->( $handler, { Data => $elt->pcdata }); }
elsif( $elt->is_cdata)
{ if( my $start_cdata= $handler->can( 'start_cdata'))
{ $start_cdata->( $handler); }
if( my $characters= $handler->can( 'characters'))
{ $characters->( $handler, {Data => $elt->cdata }); }
if( my $end_cdata= $handler->can( 'end_cdata'))
{ $end_cdata->( $handler); }
}
elsif( ($elt->is_pi) && (my $pi= $handler->can( 'processing_instruction')))
{ $pi->( $handler, { Target =>$elt->target, Data => $elt->data }); }
elsif( ($elt->is_comment) && (my $comment= $handler->can( 'comment')))
{ $comment->( $handler, { Data => $elt->comment }); }
lib/XML/Twig.pm view on Meta::CPAN
$child= $child->_next_sibling;
}
return 0;
}
# creates a single pcdata element containing the text as child of the element
# options:
# - force_pcdata: when set to a true value forces the text to be in a #PCDATA
# even if the original element was a #CDATA
sub set_text
{ my( $elt, $string, %option)= @_;
if( $elt->gi eq $PCDATA)
{ return $elt->set_pcdata( $string); }
elsif( $elt->gi eq $CDATA)
{ if( $option{force_pcdata})
{ $elt->set_gi( $PCDATA);
$elt->_set_cdata('');
return $elt->set_pcdata( $string);
}
else
{ $elt->_set_cdata( $string);
return $string;
}
}
elsif( $elt->contains_a_single( $PCDATA) )
{ # optimized so we have a slight chance of not losing embedded comments and pi's
$elt->_first_child->set_pcdata( $string);
return $elt;
}
foreach my $child (@{[$elt->_children]})
{ $child->delete; }
my $pcdata= $elt->_new_pcdata( $string);
$pcdata->paste( $elt);
$elt->set_not_empty;
return $elt;
}
lib/XML/Twig.pm view on Meta::CPAN
&& (@_ == 1) && !( ref $_[0]))
{ $elt->set_text( $_[0]);
return $elt;
}
elsif( ($elt->gi eq $CDATA) && (@_ == 1) && !( ref $_[0]))
{ $elt->_set_cdata( $_[0]);
return $elt;
}
# delete the children
foreach my $child (@{[$elt->_children]})
lib/XML/Twig.pm view on Meta::CPAN
{ # argument is an element
$child->paste( 'last_child', $elt);
}
else
{ # argument is a string
if( (my $pcdata= $elt->_last_child) && $elt->_last_child->is_pcdata)
{ # previous child is also pcdata: just concatenate
$pcdata->set_pcdata( $pcdata->pcdata . $child)
}
else
{ # previous child is not a string: create a new pcdata element
$pcdata= $elt->_new_pcdata( $child);
$pcdata->paste( 'last_child', $elt);
}
}
}
return $elt;
lib/XML/Twig.pm view on Meta::CPAN
$elt->cut;
$elt->paste( @_);
return $elt;
}
# adds a prefix to an element, creating a pcdata child if needed
sub prefix
{ my ($elt, $prefix, $option)= @_;
my $asis= ($option && ($option eq 'asis')) ? 1 : 0;
if( $elt->is_pcdata
&& (($asis && $elt->{asis}) || (!$asis && ! $elt->{asis}))
)
{ $elt->set_pcdata( $prefix . $elt->pcdata); }
elsif( $elt->_first_child && $elt->_first_child->is_pcdata
&& ( ($asis && $elt->_first_child->{asis})
|| (!$asis && ! $elt->_first_child->{asis}))
)
{
$elt->_first_child->set_pcdata( $prefix . $elt->_first_child->pcdata);
}
else
{ my $new_elt= $elt->_new_pcdata( $prefix);
my $pos= $elt->is_pcdata ? 'before' : 'first_child';
$new_elt->paste( $pos => $elt);
if( $asis) { $new_elt->set_asis; }
}
return $elt;
}
# adds a suffix to an element, creating a pcdata child if needed
sub suffix
{ my ($elt, $suffix, $option)= @_;
my $asis= ($option && ($option eq 'asis')) ? 1 : 0;
if( $elt->is_pcdata
&& (($asis && $elt->{asis}) || (!$asis && ! $elt->{asis}))
)
{ $elt->set_pcdata( $elt->pcdata . $suffix); }
elsif( $elt->_last_child && $elt->_last_child->is_pcdata
&& ( ($asis && $elt->_last_child->{asis})
|| (!$asis && ! $elt->_last_child->{asis}))
)
{ $elt->_last_child->set_pcdata( $elt->_last_child->pcdata . $suffix); }
else
{ my $new_elt= $elt->_new_pcdata( $suffix);
my $pos= $elt->is_pcdata ? 'after' : 'last_child';
$new_elt->paste( $pos => $elt);
if( $asis) { $new_elt->set_asis; }
}
return $elt;
}
lib/XML/Twig.pm view on Meta::CPAN
if( exists $option->{depth}) { $option->{depth}--; }
$dump .= join( "", map { $_->_dump( $option) } $elt->_children) unless exists $option->{depth} && $option->{depth} <= 0;
}
else
{
if( $elt->is_pcdata)
{ $dump .= "$indent|-PCDATA: '" . _short_text( $elt->pcdata, $short_text) . "'\n" }
elsif( $elt->is_ent)
{ $dump .= "$indent|-ENTITY: '" . _short_text( $elt->ent, $short_text) . "'\n" }
elsif( $elt->is_cdata)
{ $dump .= "$indent|-CDATA: '" . _short_text( $elt->cdata, $short_text) . "'\n" }
elsif( $elt->is_comment)
{ $dump .= "$indent|-COMMENT: '" . _short_text( $elt->comment_string, $short_text) . "'\n" }
elsif( $elt->is_pi)
{ $dump .= "$indent|-PI: '" . $elt->target . "' - '" . _short_text( $elt->data, $short_text) . "'\n" }
if( $extra) { $dump .= $elt->_dump_extra_data( $indent, $indent_sp, $short_text); }
lib/XML/Twig.pm view on Meta::CPAN
if( $elt->extra_data)
{ my $extra_data = $indent . "|-- (cpi before) '" . _short_text( $elt->extra_data, $short_text) . "'";
$extra_data=~ s{\n}{$indent_sp}g;
$dump .= $extra_data . "\n";
}
if( $elt->_extra_data_in_pcdata)
{ foreach my $data ( @{$elt->_extra_data_in_pcdata})
{ my $extra_data = $indent . "|-- (cpi offset $data->{offset}) '" . _short_text( $data->{text}, $short_text) . "'";
$extra_data=~ s{\n}{$indent_sp}g;
$dump .= $extra_data . "\n";
}
}
lib/XML/Twig.pm view on Meta::CPAN
=item input_filter
This option is similar to C<output_filter> except the filter is applied to
the characters before they are stored in the twig, at parsing time.
=item remove_cdata
Setting this option to a true value will force the twig to output C<#CDATA>
sections as regular (escaped) C<#PCDATA>.
=item parse_start_tag
lib/XML/Twig.pm view on Meta::CPAN
<!ELEMENT foo (#PCDATA|bar)>
then a C<foo> element including a C<bar> one will be printed as:
<foo>
<bar>bar is just pcdata</bar>
</foo>
This is invalid, as the parser will take the line break after the C<foo> tag
as a sign that the element contains PCDATA, it will then die when it finds the
C<bar> tag. This may or may not be important for you, but be aware of it!
lib/XML/Twig.pm view on Meta::CPAN
are kept at their original position in the text. Using "print"
methods like C<print> or C<sprint> will return the comments in the
text. Using C<text> or C<field> on the other hand will not.
Any use of C<set_pcdata> on the C<#PCDATA> element (directly or
through other methods like C<set_content>) will delete the comment(s).
=item process
Comments are loaded in the twig and are treated as regular elements
lib/XML/Twig.pm view on Meta::CPAN
C<normal> outputs an empty tag 'C<< <tag/> >>', C<html> adds a space
'C<< <tag /> >>' for elements that can be empty in XHTML, and C<expand> outputs
'C<< <tag></tag> >>'.
=item set_remove_cdata ($flag)
Sets (or unsets) the flag that forces the twig to output C<#CDATA> sections as
regular (escaped) C<#PCDATA>.
=item print_prolog ($optional_filehandle, %options)
lib/XML/Twig.pm view on Meta::CPAN
=item in_context ($cond, $optional_level)
Returns true (the matching including element) if the element is included in an element which passes C<$cond>
optionally within C<$optional_level> levels, otherwise false (0).
=item pcdata
Returns the text of a C<#PCDATA> element or C<undef> if the element is not
C<#PCDATA>.
=item pcdata_xml_string
Returns the text of a C<#PCDATA> element or C<undef> if the element is not C<#PCDATA>.
The text is "XML-escaped" ('&' and '<' are replaced by '&' and '<').
=item set_pcdata ($text)
Sets the text of a C<#PCDATA> element. This method does not check that the element is
indeed a C<#PCDATA> so usually you should use C<L<set_text> > instead.
=item append_pcdata ($text)
Adds the text at the end of a C<#PCDATA> element.
=item is_cdata
Returns true (1) if the element is a C<#CDATA> element, returns false ('') otherwise.
=item is_text
Returns true (1) if the element is a C<#CDATA> or C<#PCDATA> element, returns false ('') otherwise.
=item cdata
Returns the text of a C<#CDATA> element or C<undef> if the element is not
C<#CDATA>.
=item cdata_string
Returns the XML string of a C<#CDATA> element, including the opening and
closing markers.
=item set_cdata ($text)
Sets the text of a C<#CDATA> element.
=item append_cdata ($text)
Adds the text at the end of a C<#CDATA> element.
=item remove_cdata
Turns all C<#CDATA> sections in the element into regular C<#PCDATA> elements. This is useful
when converting XML to HTML, as browsers do not support CDATA sections.
=item extra_data
lib/XML/Twig.pm view on Meta::CPAN
=item is_field
Same as C<contains_only_text>.
=item is_pcdata
Returns true (1) if the element is a C<#PCDATA> element, otherwise returns false ('').
=item is_ent
lib/XML/Twig.pm view on Meta::CPAN
'C<< <tag /> >>' for elements that can be empty in XHTML and C<expand> outputs
'C<< <tag></tag> >>'.
Returns the previous setting.
=item set_remove_cdata ($flag)
Sets (or unsets) the flag that forces the twig to output C<#CDATA> sections as
regular (escaped) C<#PCDATA>.
Returns the previous setting.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Writer/Lazy.pm view on Meta::CPAN
my $data = shift;
return;
}
# No work needed, as the insides will already be magically quoted
sub start_cdata { return; }
sub end_cdata { return; }
sub not_implemented {
my ($event) = @_;
return <<"MSG";
The XML passed to 'lazily()' triggered a `$event` SAX event,
view all matches for this distribution
view release on metacpan or search on metacpan
scripts/mkxmlwritersimple view on Meta::CPAN
die "No file supplied\n" unless $xmlfile && -f $xmlfile;
my %tags;
my $code = dt( $xmlfile,
-pcdata => sub {
return "" if $c =~ m/^[\s\n\r]+$/;
$c =~ s/"/\\"/g;
$c =~ s/\$/\\\$/g;
'"' . $c . '",';
},
view all matches for this distribution
view release on metacpan or search on metacpan
my $SAFE_raw = sub {
croak('raw() is only available when UNSAFE is set');
};
my $cdata = sub {
my $data = $_[0];
$data =~ s/\]\]>/\]\]\]\]><!\[CDATA\[>/g;
$output->print("<![CDATA[$data]]>");
$hasData = 1;
};
my $SAFE_cdata = sub {
if ($elementLevel < 1) {
croak("Attempt to insert characters outside of document element");
} elsif ($dataMode && $hasElement) {
croak("Mixed content not allowed in data mode: characters");
} else {
_croakUnlessDefinedCharacters($_[0]);
&{$checkUnencodedRepertoire}($_[0]);
&{$cdata};
}
};
# Assign the correct closures based on
# the UNSAFE parameter
'STARTTAG' => $startTag,
'EMPTYTAG' => $emptyTag,
'ENDTAG' => $endTag,
'CHARACTERS' => $characters,
'RAW' => $raw,
'CDATA' => $cdata
};
} else {
$self = {'END' => $SAFE_end,
'XMLDECL' => $SAFE_xmlDecl,
'PI' => $SAFE_pi,
'STARTTAG' => $SAFE_startTag,
'EMPTYTAG' => $SAFE_emptyTag,
'ENDTAG' => $SAFE_endTag,
'CHARACTERS' => $SAFE_characters,
'RAW' => $SAFE_raw, # This will intentionally fail
'CDATA' => $SAFE_cdata
};
}
# Query methods
$self->{'IN_ELEMENT'} = sub {
}
#
# Write a simple CDATA element.
#
sub cdataElement {
my ($self, $name, $data, %atts) = (@_);
$self->startTag($name, %atts);
$self->cdata($data);
$self->endTag($name);
}
#
# Write character data.
}
#
# Write CDATA.
#
sub cdata {
my $self = shift;
&{$self->{CDATA}};
}
#
This can sometimes be useful for printing entities which are defined
for your XML format but the module doesn't know about, for example
for XHTML.
=item cdata($data)
As C<characters()> but writes the data quoted in a CDATA section, that
is, between <![CDATA[ and ]]>. If the data to be written itself
contains ]]>, it will be written as several consecutive CDATA
sections.
=item cdataElement($name, $data [, $aname1 => $value1, ...])
As C<dataElement()> but the element content is written as one or more
CDATA sections (see C<cdata()>).
=item setOutput($output)
Set the current output destination, as in the OUTPUT parameter for the
constructor.
view all matches for this distribution
view release on metacpan or search on metacpan
XMLWriter.pm view on Meta::CPAN
my $doc = new XML::XMLWriter(system => 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd',
public => '-//W3C//DTD XHTML 1.0 Transitional//EN');
my $html = $doc->createRoot;
$html->head->title->_pcdata('A Table');
my $body = $html->body;
$body->h1->_pcdata('Here is a table!');
my $table = $body->table({align => 'center', cellspacing => 1, cellpadding => 2, border => 1});
for(my $i=0; $i<@data; $i++) {
my $tr = $table->tr;
foreach $_ (@{$data[$i]}) {
$i==0 ? $tr->th->_pcdata($_) : $tr->td->_pcdata($_);
}
}
$body->b->_pcdata("that's it!");
$doc->print();
=head2 Example Output
<?xml version="1.0" encoding="ISO-8859-15" standalone="no"?>
XMLWriter.pm view on Meta::CPAN
the start tag. Defaults to undef, which means no data will be added.
=back
Instead of passing the third argument you can also just do a
C<$root-E<gt>_pcdata(yourdata)>, its exactly the same.
=cut
######################################################################
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XOXO/Node.pm view on Meta::CPAN
'\'' => '''
);
my $RE = join '|', keys %Map;
sub encode_xml {
my ( $str, $nocdata ) = @_;
return unless defined($str);
if (
!$nocdata
&& $str =~ m/
<[^>]+> ## HTML markup
| ## or
&(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?);
## something that looks like an HTML entity.
view all matches for this distribution
view release on metacpan or search on metacpan
samples/REC-xml-19980210.xml view on Meta::CPAN
may be used for
formal declaration of PI targets.
</p>
</div2>
<div2 id='sec-cdata-sect'>
<head>CDATA Sections</head>
<p><termdef id="dt-cdsection" term="CDATA Section"><term>CDATA sections</term>
may occur
anywhere character data may occur; they are
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XSH/Completion.pm view on Meta::CPAN
our $match_no_xpath=join '|',@XML::XSH::CompletionList::XSH_NOXPATH_COMMANDS;
our $match_no=qr/${M}(?:${match_no_xpath}|create\s+[a-zA-Z0-9_]*\s)\s*$/;
# PATH-completion: system, !, exec, |,
our @nodetypes = qw(element attribute attributes text cdata pi comment chunk entity_reference);
our @openflags1 = qw(HTML XML DOCBOOK);
our @openflags2 = qw(FILE PIPE STRING);
our @saveflags1 = qw(HTML XML XINCLUDE);
our @saveflags2 = qw(FILE PIPE STRING);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XSH2/Completion.pm view on Meta::CPAN
our $OPER = qr/(?:[,=<>\+\|]|-(?!$NAME)|(?:vid|dom|dna|ro)(?=\s*\]|\s*\)|\s*[0-9]+(?!$NNAMECHAR)|\s+{$NAMECHAR}|\s+\*))/;
# PATH-completion: system, !, exec, |,
our @nodetypes = qw(element attribute attributes text cdata pi comment chunk entity_reference);
sub complete_option {
my ($l)=@_;
if ($l=~/\s--encoding\s+$|\s:e\s+$/) {
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XSLT.pm view on Meta::CPAN
# Revision 1.16 2002/01/09 09:17:40 gellyfish
# * added test for <xsl:text>
# * Stylesheet whitespace stripping as per spec and altered tests ...
#
# Revision 1.15 2002/01/08 10:11:47 gellyfish
# * First cut at cdata-section-element
# * test for above
#
# Revision 1.14 2001/12/24 16:00:19 gellyfish
# * Version released to CPAN
#
lib/XML/XSLT.pm view on Meta::CPAN
$self->doctype_public($dp);
my $ds = defined $doctype_system ? $doctype_system->getNodeValue : '';
$self->doctype_system($ds);
# cdata-section-elements should only be used if the output type
# is XML but as we are not checking that right now ...
my $cdata_section = $attribs->getNamedItem('cdata-section-elements');
if ( defined $cdata_section )
{
my $cdata_sections = [];
@{$cdata_sections} = split /\s+/, $cdata_section->getNodeValue();
$self->cdata_sections($cdata_sections);
}
}
else
{
$self->debug("Default Output options being used");
lib/XML/XSLT.pm view on Meta::CPAN
}
return exists $self->{OMIT_XML_DECL} ? $self->{OMIT_XML_DECL} : 0;
}
sub cdata_sections
{
my ( $self, $cdata_sections ) = @_;
if ( defined $cdata_sections )
{
$self->{CDATA_SECTIONS} = $cdata_sections;
}
$self->{CDATA_SECTIONS} = [] unless exists $self->{CDATA_SECTIONS};
return wantarray() ? @{ $self->{CDATA_SECTIONS} } : $self->{CDATA_SECTIONS};
}
sub is_cdata_section
{
my ( $self, $element ) = @_;
my %cdata_sections;
my @cdata_temp = $self->cdata_sections();
@cdata_sections{@cdata_temp} = (1) x @cdata_temp;
my $tagname;
if ( defined $element and ref($element) and ref($element) eq 'XML::DOM' )
{
lib/XML/XSLT.pm view on Meta::CPAN
$tagname = $element;
}
# Will need to do namespace checking on this really
return exists $cdata_sections{$tagname} ? 1 : 0;
}
sub output_version
{
my ( $self, $output_version ) = @_;
lib/XML/XSLT.pm view on Meta::CPAN
{
$self->debug( $ns . " does not match " . $self->xsl_ns() );
# not entirely sure if this right but the spec is a bit vague
if ( $self->is_cdata_section($xsl_tag) )
{
$self->debug("This is a CDATA section element");
$self->_add_cdata_section( $xsl_node, $current_xml_node,
$current_xml_selection_path, $current_result_node, $variables,
$oldvariables );
}
else
{
lib/XML/XSLT.pm view on Meta::CPAN
}
$self->_outdent();
}
sub _add_cdata_section
{
my ( $self, $xsl_node, $current_xml_node, $current_xml_selection_path,
$current_result_node, $variables, $oldvariables )
= @_;
my $node = $self->xml_document()->createElement( $xsl_node->getTagName );
my $cdata = '';
foreach my $child_node ( $xsl_node->getChildNodes() )
{
if ( $child_node->can('asString') )
{
$cdata .= $child_node->asString();
}
else
{
$cdata .= $child_node->getNodeValue();
}
}
$node->addCDATA($cdata);
$current_result_node->appendChild($node);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XSPF.pm view on Meta::CPAN
$writer->startTag('track');
for my $element (qw(location identifier)) {
for my $cdata (@{$track->get("${element}s")}) {
$writer->dataElement($element, $cdata);
}
}
for my $element (qw(link meta)) {
for my $cdata (@{$track->get("${element}s")}) {
$writer->startTag($element, 'rel' => $cdata->[0]);
$writer->characters($cdata->[1]);
$writer->endTag($element);
}
}
for my $element (qw(title creator annotation info image album trackNum duration)) {
lib/XML/XSPF.pm view on Meta::CPAN
my $path = $parser->{'_xspf'}->{'path'} .= "/$element";
my $self = $parser->{'_xspf'}->{'self'};
push @{ $parser->{'_xspf'}->{'states'} }, {
'attributes' => \%attributes,
'cdata' => '',
'path' => $path,
};
# Set some default types once we encounter them.
if ($path eq '/playlist/attribution') {
lib/XML/XSPF.pm view on Meta::CPAN
my ($parser, $value) = @_;
# Keep the our little state machine chugging along
my $state = pop @{ $parser->{'_xspf'}->{'states'} };
$state->{'cdata'} .= $value;
push @{ $parser->{'_xspf'}->{'states'} }, $state;
}
sub handleEndElement {
my ($parser, $element) = @_;
my $state = pop @{ $parser->{'_xspf'}->{'states'} };
my $value = $state->{'cdata'};
my $path = $parser->{'_xspf'}->{'path'};
my $self = $parser->{'_xspf'}->{'self'};
# These are all single value elements.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/XSS/Text.pm
t/00-compile.t
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/basic.t
t/cdata.t
t/document.t
t/element.t
t/escaping.t
t/lib/A.pm
t/lib/Beta.pm
view all matches for this distribution
view release on metacpan or search on metacpan
docs/XMLUni.txt view on Meta::CPAN
fgXercesStandardUriConformant: http://apache.org/xml/features/standard-uri-conformant
fgSAX2CoreValidation: http://xml.org/sax/features/validation
fgSAX2CoreNameSpaces: http://xml.org/sax/features/namespaces
fgSAX2CoreNameSpacePrefixes: http://xml.org/sax/features/namespace-prefixes
fgDOMCanonicalForm: canonical-form
fgDOMCDATASections: cdata-sections
fgDOMComments: comments
fgDOMCharsetOverridesXMLEncoding: charset-overrides-xml-encoding
fgDOMDatatypeNormalization: datatype-normalization
fgDOMEntities: entities
fgDOMInfoset: infoset
docs/XMLUni.txt view on Meta::CPAN
fgDOMWRTCanonicalForm: canonical-form
fgDOMWRTDiscardDefaultContent: discard-defaullt-content
fgDOMWRTEntities: entities
fgDOMWRTFormatPrettyPrint: format-pretty-print
fgDOMWRTNormalizeCharacters: normalize-characters
fgDOMWRTSplitCdataSections: split-cdata-sections
fgDOMWRTValidation: validation
fgDOMWRTWhitespaceInElementContent: whitespace-in-element-content
fgDOMWRTBOM: http://apache.org/xml/features/dom/byte-order-mark
fgXercescDefaultLocale: en_US
view all matches for this distribution
view release on metacpan or search on metacpan
regerror.cc view on Meta::CPAN
#if !defined(_WIN32) && !defined(__DragonFly__) && !defined(__NetBSD__)
#define _XSFW_SKIP_CHECK 1
#endif
void register_error_constants () {
struct ecdata {
panda::string_view long_name;
panda::string_view short_name;
std::errc value;
};
Stash errc_stash("XS::STL::errc", GV_ADD);
std::initializer_list<ecdata> list = {
{"address_family_not_supported", "EAFNOSUPPORT", std::errc::address_family_not_supported},
{"address_in_use", "EADDRINUSE", std::errc::address_in_use},
{"address_not_available", "EADDRNOTAVAIL", std::errc::address_not_available},
{"already_connected", "EISCONN", std::errc::already_connected},
{"argument_list_too_long", "E2BIG", std::errc::argument_list_too_long},
view all matches for this distribution
view release on metacpan or search on metacpan
t/pkgconfig/mylib.pc
t/pkgconfig/mylib1.pc
t/pkgconfig/mylib2.pc
t/pkgconfig/pkgconfig.t
t/src.t
t/testmod/data/ccdat/ccdata1.bin
t/testmod/data/ccdat/ccdata2.bin
t/testmod/data/data.txt
t/testmod/data/db.db
t/testmod/file1.c
t/testmod/file1.h
t/testmod/file2.cc
view all matches for this distribution
view release on metacpan or search on metacpan
include/parse_subsignature_ex.h view on Meta::CPAN
OP *XPS_parse_subsignature_ex(pTHX_ int flags,
struct XPSContextWithPointer *ctx,
struct HooksAndData hooksanddata[],
size_t nhooks);
#define register_subsignature_attribute(name, funcs, funcdata) XPS_register_subsignature_attribute(aTHX_ name, funcs, funcdata)
void XPS_register_subsignature_attribute(pTHX_ const char *name, const struct XPSSignatureAttributeFuncs *funcs, void *funcdata);
view all matches for this distribution
view release on metacpan or search on metacpan
include/boost/test/impl/junit_log_formatter.ipp view on Meta::CPAN
<< " message" << utils::attr_value() << log.logentry_message
<< " type" << utils::attr_value() << log.logentry_type
<< ">";
if(!log.output.empty()) {
m_stream << utils::cdata() << "\n" + log.output;
}
m_stream << "</" << entry_type << ">";
}
struct conditional_cdata_helper {
std::ostream &ostr;
std::string const field;
bool empty;
conditional_cdata_helper(std::ostream &ostr_, std::string field_)
: ostr(ostr_)
, field(field_)
, empty(true)
{}
~conditional_cdata_helper() {
if(!empty) {
ostr << BOOST_TEST_L( "]]>" ) << "</" << field << '>' << std::endl;
}
}
include/boost/test/impl/junit_log_formatter.ipp view on Meta::CPAN
void write_testcase_system_out(junit_impl::junit_log_helper const &detailed_log,
test_unit const * tu,
bool skipped) const
{
// system-out + all info/messages, the object skips the empty entries
conditional_cdata_helper system_out_helper(m_stream, "system-out");
// indicate why the test has been skipped first
if( skipped ) {
std::list<std::string> skipping_decision_chain = build_skipping_chain(*tu);
for(list_str_citerator it(skipping_decision_chain.begin()), ite(skipping_decision_chain.end());
include/boost/test/impl/junit_log_formatter.ipp view on Meta::CPAN
}
if(!detailed_log.system_err.empty())
o << std::endl << "STDERR END ------------" << std::endl;
conditional_cdata_helper system_err_helper(m_stream, "system-err");
system_err_helper(o.str());
}
}
int get_nb_assertions(junit_impl::junit_log_helper const &detailed_log,
view all matches for this distribution
view release on metacpan or search on metacpan
c-ares-1.34.3/Makefile.netware view on Meta::CPAN
ifeq ($(DB),DEBUG)
@echo $(DL)debug$(DL) >> $@
endif
@echo $(DL)threadname "$^"$(DL) >> $@
ifdef XDCOPT
@echo $(DL)xdcdata $(@:.def=.xdc)$(DL) >> $@
endif
ifeq ($(LDRING),0)
@echo $(DL)flag_on 16$(DL) >> $@
endif
ifeq ($(LDRING),3)
view all matches for this distribution
view release on metacpan or search on metacpan
libdwarf-code-0.11.1/src/bin/dwarfgen/irepform.h view on Meta::CPAN
IRFormExprloc & operator=(const IRFormExprloc &r) {
if (this == &r) return *this;
finalform_ = r.finalform_;
initialform_ = r.initialform_;
formclass_ = r.formclass_;
exprlocdata_ = r.exprlocdata_;
return *this;
};
IRFormExprloc(const IRFormExprloc &r) {
finalform_ = r.finalform_;
initialform_ = r.initialform_;
formclass_ = r.formclass_;
exprlocdata_ = r.exprlocdata_;
}
virtual IRFormExprloc * clone() const {
return new IRFormExprloc(*this);
}
void setInitialForm(Dwarf_Half v) { initialform_ = v;}
void setFinalForm(Dwarf_Half v) { finalform_ = v;}
Dwarf_Half getInitialForm() { return initialform_;}
Dwarf_Half getFinalForm() {return finalform_;}
enum Dwarf_Form_Class getFormClass() const { return formclass_; };
std::vector<char> getexprlocdata() const {return exprlocdata_; };
void insertBlock(Dwarf_Unsigned len, Dwarf_Ptr data) {
char *d = static_cast<char *>(data);
exprlocdata_.clear();
exprlocdata_.insert(exprlocdata_.end(),d+0,d+len);
};
private:
Dwarf_Half finalform_;
// In most cases directform == indirect form.
// Otherwise, directform == DW_FORM_indirect.
Dwarf_Half initialform_;
enum Dwarf_Form_Class formclass_;
std::vector<char> exprlocdata_;
};
class IRFormFlag : public IRForm {
public:
IRFormFlag():
view all matches for this distribution
view release on metacpan or search on metacpan
geos-3.7.3/tests/xmltester/tinyxml/tinyxml.cpp view on Meta::CPAN
void TiXmlText::Print( FILE* cfile, int depth ) const
{
assert( cfile );
if ( cdata )
{
int i;
fprintf( cfile, "\n" );
for ( i=0; i<depth; i++ ) {
fprintf( cfile, " " );
geos-3.7.3/tests/xmltester/tinyxml/tinyxml.cpp view on Meta::CPAN
void TiXmlText::CopyTo( TiXmlText* target ) const
{
TiXmlNode::CopyTo( target );
target->cdata = cdata;
}
bool TiXmlText::Accept( TiXmlVisitor* visitor ) const
{
view all matches for this distribution
view release on metacpan or search on metacpan
range-v3-0.12.0/doc/release_notes.md view on Meta::CPAN
- `ranges::cbegin`
- `ranges::cend`
- `ranges::crbegin`
- `ranges::crend`
- `ranges::data`
- `ranges::cdata`
* Iterators may specify an `iterator_concept` type alias in addition to
`iterator_category` -- either as a nested type or as a member of a
`std::iterator_traits` specialization -- to denote conformance to the C++20
iterator concepts as distinct from the C++98 iterator requirements.
(See [P1037 "Deep Integration of the Ranges TS"](http://wg21.link/p1037)
view all matches for this distribution
view release on metacpan or search on metacpan
lib/blx/xsdsql/xml/reader.pm view on Meta::CPAN
,Entity => \&_entity_node
,Element => \&_element_node
,Attlist => \&_attlist_node
,ExternEnt => \&_externent_node
,DoctypeFin => \&_doctypefin_node
# ,CDataStart => \&_cdatastart_node
,XMLDecl => \&_xmldecl_node
);
$class->SUPER::_new(%params);
}
view all matches for this distribution
view release on metacpan or search on metacpan
share/js/jslib/utils/sax.js view on Meta::CPAN
this.str = this.str.substring(close + 1,this.str.length);
continue;
}
// leftovers are cdata
if(estart == -1)
{
this.handler.characters(this.entityCheck(this.str));
this.str = "";
}else{
view all matches for this distribution