view release on metacpan or search on metacpan
lib/XML/SAX/Builder.pm view on Meta::CPAN
my $self = shift;
XML::SAX::Builder::Namespace->new( $self->{ Handler }, @_ );
}
# Output unescaped stuff.
sub xmlcdata {
my $self = shift;
XML::SAX::Builder::CDATA->new( $self->{ Handler }, @_ );
}
# Output an XML DOCTYPE
lib/XML/SAX/Builder.pm view on Meta::CPAN
Carp::croak "arguments must be character data only"
if grep { ref } @args;
@args = grep { defined } @args;
return sub {
my ( $self, $nsup ) = @_;
$handler->start_cdata( {} );
$handler->characters( { Data => join ( '', @args ) } );
$handler->end_cdata( {} );
};
}
#---------------------------------------------------------------------
lib/XML/SAX/Builder.pm view on Meta::CPAN
This method inserts a new namespace into the resulting XML. PREFIX and
URI are the namespace prefix and uri. CHILD is either an element
object, or another namespace object.
=item xmlcdata ( TEXT, [ TEXT ] )
Inserts all arguments concatenated together inside a E<lt>![CDATA block.
=item xmldtd ( ELEMENT, SYSTEM [, PUBLIC ] )
view all matches for this distribution
view release on metacpan or search on metacpan
Start => \&_handle_start,
End => \&_handle_end,
Char => \&_handle_char,
Comment => \&_handle_comment,
Proc => \&_handle_proc,
CdataStart => \&_handle_start_cdata,
CdataEnd => \&_handle_end_cdata,
Unparsed => \&_handle_unparsed_entity,
Notation => \&_handle_notation_decl,
#ExternEnt
#ExternEntFin
Entity => \&_handle_entity_decl,
$_[0]->{__XSE}->SUPER::processing_instruction({ Target => $_[1], Data => $_[2] });
}
#-------------------------------------------------------------------#
#-------------------------------------------------------------------#
# _handle_start_cdata
#-------------------------------------------------------------------#
sub _handle_start_cdata {
$_[0]->{__XSE}->SUPER::start_cdata( {} );
}
#-------------------------------------------------------------------#
#-------------------------------------------------------------------#
# _handle_end_cdata
#-------------------------------------------------------------------#
sub _handle_end_cdata {
$_[0]->{__XSE}->SUPER::end_cdata( {} );
}
#-------------------------------------------------------------------#
#-------------------------------------------------------------------#
# _handle_xml_decl
view all matches for this distribution
view release on metacpan or search on metacpan
SAVETMPS;
PUSHMARK(sp);
XPUSHs(cbv->self_sv);
PUTBACK;
perl_call_method("start_cdata", G_DISCARD);
FREETMPS;
LEAVE;
} /* End startCdata */
SAVETMPS;
PUSHMARK(sp);
XPUSHs(cbv->self_sv);
PUTBACK;
perl_call_method("end_cdata", G_DISCARD);
FREETMPS;
LEAVE;
} /* End endCdata */
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/SAX/EventMethodMaker.pm view on Meta::CPAN
internal_entity_decl Han;----;----;----;----;Dec
external_entity_decl Han;----;----;----;----;Dec
comment Han;----;----;----;Lex
start_dtd Han;----;----;----;Lex
end_dtd Han;----;----;----;Lex
start_cdata Han;----;----;----;Lex
end_cdata Han;----;----;----;Lex
start_entity Han;----;----;----;Lex
end_entity Han;----;----;----;Lex
warning Han;----;----;----;----;----;Err
error Han;----;----;----;----;----;Err
fatal_error Han;----;----;----;----;----;Err
view all matches for this distribution
view release on metacpan or search on metacpan
t/1_XMLin.t view on Meta::CPAN
ok(24, DataCompare($opt, $target));
# confirm that CDATA sections parse correctly
$xml = q{<opt><cdata><![CDATA[<greeting>Hello, world!</greeting>]]></cdata></opt>};
$opt = XMLin($xml);
ok(25, DataCompare($opt, {
'cdata' => '<greeting>Hello, world!</greeting>'
}));
$xml = q{<opt><x><![CDATA[<y>one</y>]]><![CDATA[<y>two</y>]]></x></opt>};
$opt = XMLin($xml);
ok(26, DataCompare($opt, {
view all matches for this distribution
view release on metacpan or search on metacpan
inc/XML/SAX/Base.pm view on Meta::CPAN
}
}
}
sub end_cdata {
my $self = shift;
if (defined $self->{Methods}->{'end_cdata'}) {
$self->{Methods}->{'end_cdata'}->(@_);
}
else {
my $method;
my $callbacks;
if (exists $self->{ParseOptions}) {
inc/XML/SAX/Base.pm view on Meta::CPAN
else {
$callbacks = $self;
}
if (0) { # dummy to make elsif's below compile
}
elsif (defined $callbacks->{'DocumentHandler'} and $method = $callbacks->{'DocumentHandler'}->can('end_cdata') ) {
my $handler = $callbacks->{'DocumentHandler'};
$self->{Methods}->{'end_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'LexicalHandler'} and $method = $callbacks->{'LexicalHandler'}->can('end_cdata') ) {
my $handler = $callbacks->{'LexicalHandler'};
$self->{Methods}->{'end_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'Handler'} and $method = $callbacks->{'Handler'}->can('end_cdata') ) {
my $handler = $callbacks->{'Handler'};
$self->{Methods}->{'end_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'DocumentHandler'}
and $callbacks->{'DocumentHandler'}->can('AUTOLOAD')
and $callbacks->{'DocumentHandler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'DocumentHandler'}->end_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'DocumentHandler'};
$self->{Methods}->{'end_cdata'} = sub { $handler->end_cdata(@_) };
}
return $res;
}
elsif (defined $callbacks->{'LexicalHandler'}
and $callbacks->{'LexicalHandler'}->can('AUTOLOAD')
and $callbacks->{'LexicalHandler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'LexicalHandler'}->end_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'LexicalHandler'};
$self->{Methods}->{'end_cdata'} = sub { $handler->end_cdata(@_) };
}
return $res;
}
elsif (defined $callbacks->{'Handler'}
and $callbacks->{'Handler'}->can('AUTOLOAD')
and $callbacks->{'Handler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'Handler'}->end_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'Handler'};
$self->{Methods}->{'end_cdata'} = sub { $handler->end_cdata(@_) };
}
return $res;
}
else {
$self->{Methods}->{'end_cdata'} = sub { };
}
}
}
inc/XML/SAX/Base.pm view on Meta::CPAN
}
}
}
sub start_cdata {
my $self = shift;
if (defined $self->{Methods}->{'start_cdata'}) {
$self->{Methods}->{'start_cdata'}->(@_);
}
else {
my $method;
my $callbacks;
if (exists $self->{ParseOptions}) {
inc/XML/SAX/Base.pm view on Meta::CPAN
else {
$callbacks = $self;
}
if (0) { # dummy to make elsif's below compile
}
elsif (defined $callbacks->{'DocumentHandler'} and $method = $callbacks->{'DocumentHandler'}->can('start_cdata') ) {
my $handler = $callbacks->{'DocumentHandler'};
$self->{Methods}->{'start_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'LexicalHandler'} and $method = $callbacks->{'LexicalHandler'}->can('start_cdata') ) {
my $handler = $callbacks->{'LexicalHandler'};
$self->{Methods}->{'start_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'Handler'} and $method = $callbacks->{'Handler'}->can('start_cdata') ) {
my $handler = $callbacks->{'Handler'};
$self->{Methods}->{'start_cdata'} = sub { $method->($handler, @_) };
return $method->($handler, @_);
}
elsif (defined $callbacks->{'DocumentHandler'}
and $callbacks->{'DocumentHandler'}->can('AUTOLOAD')
and $callbacks->{'DocumentHandler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'DocumentHandler'}->start_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'DocumentHandler'};
$self->{Methods}->{'start_cdata'} = sub { $handler->start_cdata(@_) };
}
return $res;
}
elsif (defined $callbacks->{'LexicalHandler'}
and $callbacks->{'LexicalHandler'}->can('AUTOLOAD')
and $callbacks->{'LexicalHandler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'LexicalHandler'}->start_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'LexicalHandler'};
$self->{Methods}->{'start_cdata'} = sub { $handler->start_cdata(@_) };
}
return $res;
}
elsif (defined $callbacks->{'Handler'}
and $callbacks->{'Handler'}->can('AUTOLOAD')
and $callbacks->{'Handler'}->can('AUTOLOAD') ne (UNIVERSAL->can('AUTOLOAD') || '')
)
{
my $res = eval { $callbacks->{'Handler'}->start_cdata(@_) };
if ($@) {
die $@;
}
else {
# I think there's a buggette here...
# if the first call throws an exception, we don't set it up right.
# Not fatal, but we might want to address it.
my $handler = $callbacks->{'Handler'};
$self->{Methods}->{'start_cdata'} = sub { $handler->start_cdata(@_) };
}
return $res;
}
else {
$self->{Methods}->{'start_cdata'} = sub { };
}
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/SAX/Writer/XML.pm view on Meta::CPAN
$self->{BufferDTD} = '';
}
#-------------------------------------------------------------------#
#-------------------------------------------------------------------#
# start_cdata
#-------------------------------------------------------------------#
sub start_cdata {
my $self = shift;
$self->_output_element;
$self->{InCDATA} = 1;
my $cds = $self->{Encoder}->convert('<![CDATA[');
$self->{Consumer}->output($cds);
}
#-------------------------------------------------------------------#
#-------------------------------------------------------------------#
# end_cdata
#-------------------------------------------------------------------#
sub end_cdata {
my $self = shift;
$self->{InCDATA} = 0;
my $cds = $self->{Encoder}->convert(']]>');
$self->{Consumer}->output($cds);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
$self->SUPER::start_element({Name=>"vCard",Attributes=>$attrs});
#
# FN:
$self->_pcdata({name=>"fn",value=>$vcard->{'fn'}});
# N:
$self->SUPER::start_element({Name=>"n"});
foreach ("family","given","other","prefix","suffix") {
$self->_pcdata({name=>$_,value=>$vcard->{'n'}{$_}});
}
$self->SUPER::end_element({Name=>"n"});
# NICKNAME:
if (exists($vcard->{'nickname'})) {
$self->_pcdata({name=>"nickname",value=>$vcard->{'nickname'}});
}
# PHOTO:
if (exists($vcard->{'photo'})) {
$self->_media({name=>"photo",%{$vcard->{photo}}});
}
# BDAY:
if (exists($vcard->{'bday'})) {
$self->_pcdata({name=>"bday",value=>$vcard->{'bday'}});
}
# ADR:
if (ref($vcard->{'adr'}) eq "ARRAY") {
foreach my $adr (@{$vcard->{'adr'}}) {
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
$self->SUPER::start_element({Name=>"adr",
Attributes=>{"{}del.type"=>{Name=>"del.type",Value=>$adr->{type}}}
});
foreach ("pobox","extadr","street","locality","region","pcode","country") {
$self->_pcdata({name=>$_,value=>$adr->{$_}});
}
$self->SUPER::end_element({Name=>"adr"});
}
}
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
if (ref($vcard->{'tel'}) eq "ARRAY") {
foreach my $t (@{$vcard->{'tel'}}) {
&_munge_type(\$t->{type});
$self->_pcdata({name=>"tel",value=>$t->{number},
attrs=>{"{}tel.type"=>{Name=>"tel.type",Value=>$t->{type}}}
});
}
}
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
if (ref($vcard->{'email'}) eq "ARRAY") {
foreach my $e (@{$vcard->{'email'}}) {
&_munge_type(\$e->{type});
$self->_pcdata({name=>"email",value=>$e->{address},
attrs=>{"{}email.type"=>{Name=>"email.type",Value=>$e->{type}}}
});
}
}
# MAILER:
if (exists($vcard->{'mailer'})) {
$self->_pcdata({name=>"mailer",
value=>$vcard->{'mailer'}});
}
# TZ:
if (exists($vcard->{'tz'})) {
$self->_pcdata({name=>"tz",
value=>$vcard->{'tz'}});
}
# GEO:
if (exists($vcard->{'geo'})) {
$self->SUPER::start_element({Name=>"geo"});
$self->_pcdata({name=>"lat",value=>$vcard->{'geo'}{'lat'}});
$self->_pcdata({name=>"lon",value=>$vcard->{'geo'}{'lon'}});
$self->SUPER::end_element({Name=>"geo"});
}
# TITLE:
if (exists($vcard->{'title'})) {
$self->_pcdata({name=>"title",value=>$vcard->{'title'}});
}
# ROLE
if (exists($vcard->{'role'})) {
$self->_pcdata({name=>"role",value=>$vcard->{'role'}});
}
# LOGO:
if (exists($vcard->{'logo'})) {
$self->_media({name=>"logo",%{$vcard->{'logo'}}});
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
# AGENT:
if (exists($vcard->{agent})) {
$self->SUPER::start_element({Name=>"agent"});
if ($vcard->{agent}{uri}) {
$self->_pcdata({name=>"extref",attrs=>{"{}uri"=>{Name=>"uri",
Value=>$vcard->{'agent'}{'uri'}}}
});
}
else {
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
}
# ORG:
if (exists($vcard->{'org'})) {
$self->SUPER::start_element({Name=>"org"});
$self->_pcdata({name=>"orgnam",value=>$vcard->{'org'}{'name'}});
$self->_pcdata({name=>"orgunit",value=>$vcard->{'org'}{'unit'}});
$self->SUPER::end_element({Name=>"org"});
}
# CATEGORIES:
if (ref($vcard->{'categories'}) eq "ARRAY") {
$self->SUPER::start_element({Name=>"categories"});
foreach (@{$vcard->{categories}}) {
$self->_pcdata({name=>"item",value=>$_});
}
$self->SUPER::end_element({Name=>"categories"});
}
# NOTE:
if (exists($vcard->{'note'})) {
$self->_pcdata({name=>"note",value=>$vcard->{'note'}});
}
# SORT:
if (exists($vcard->{'sort'})) {
$self->_pcdata({name=>"sort",value=>$vcard->{'sort'}});
}
# SOUND:
if (exists($vcard->{'sound'})) {
$self->_media({name=>"sound",%{$vcard->{'sound'}}});
}
# URL:
if (ref($vcard->{'url'}) eq "ARRAY") {
foreach (@{$vcard->{'url'}}) {
$self->_pcdata({name=>"url",
Attributes=>{"{}uri"=>{Name=>"uri",Value=>$_}}});
}
}
# KEY:
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
$self->SUPER::end_element({Name=>"vCard"});
return 1;
}
sub _pcdata {
my $self = shift;
my $data = shift;
$self->SUPER::start_element({Name=>$data->{name},Attributes=>$data->{attrs}});
$self->SUPER::start_cdata() if ($data->{cdata});
$self->SUPER::characters({Data=>$data->{value}});
$self->SUPER::end_cdata() if ($data->{cdata});
$self->SUPER::end_element({Name=>$data->{name}});
return 1;
}
sub _media {
lib/XML/SAXDriver/vCard.pm view on Meta::CPAN
}
$self->SUPER::start_element({Name=>$data->{name},Attributes=>$attrs});
if ($data->{url}) {
$self->_pcdata({name=>"extref",attrs=>{"{}uri"=>{Name=>"uri",
Value=>$data->{url}}}
});
}
else {
$self->_pcdata({name=>"b64bin",value=>$data->{b64},cdata=>1});
}
$self->SUPER::end_element({Name=>$data->{name}});
return 1;
}
view all matches for this distribution
view release on metacpan or search on metacpan
t/24-xml-draft-nzrs-srs-01.t view on Meta::CPAN
plan tests => @tests * 3;
my $xml_compare = XML::Compare->new(
ignore => [
q{//Error//text()}, # FIXME - cdata types
q{//DomainNameFilter/text()}, # FIXME - cdata types
q{//AuditText/text()}, # FIXME - cdata types
q{//AccessControlListQry/@FullResult},
],
);
for my $test ( sort @tests ) {
view all matches for this distribution
view release on metacpan or search on metacpan
STX/Base.pm view on Meta::CPAN
# tokens
$NCName = '[A-Za-z_][\w\\.\\-]*';
$QName = "($NCName:)?$NCName";
$NCWild = "${NCName}:\\*|\\*:${NCName}";
$QNWild = "\\*";
$NODE_TYPE = '((text|comment|processing-instruction|node|cdata)\\(\\))';
$NUMBER_RE = '\d+(\\.\d*)?|\\.\d+';
$DOUBLE_RE = '\d+(\\.\d*)?[eE][+-]?\d+';
$LITERAL = '\\"[^\\"]*\\"|\\\'[^\\\']*\\\'';
$URIREF = '[a-z][\w\;\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\'\(\)\%]+';
STX/Base.pm view on Meta::CPAN
} elsif ($seq->[0]->[0]->{Type} == STX_ATTRIBUTE_NODE) {
$type .= '-attribute';
} elsif ($seq->[0]->[0]->{Type} == STX_TEXT_NODE) {
$type .= '-text';
} elsif ($seq->[0]->[0]->{Type} == STX_CDATA_NODE) {
$type .= '-cdata';
} elsif ($seq->[0]->[0]->{Type} == STX_PI_NODE) {
$type .= '-processing-instruction';
} elsif ($seq->[0]->[0]->{Type} == STX_COMMENT_NODE) {
$type .= '-comment';
} else {
STX/Base.pm view on Meta::CPAN
sub _counter_key($) {
my ($self, $tok) = @_;
$tok =~ s/^node\(\)$/\/node/
or $tok =~ s/^text\(\)$/\/text/
or $tok =~ s/^cdata\(\)$/\/cdata/
or $tok =~ s/^comment\(\)$/\/comment/
or $tok =~ s/^processing-instruction\(\)$/\/pi/
or $tok =~ s/^processing-instruction:(.*)$/\/pi:$1/
or $tok = index($tok, ':') > 0 ? $tok : ':' . $tok;
$tok =~ s/\*/\/star/;
view all matches for this distribution
view release on metacpan or search on metacpan
=head2 getNodeName
For ELEMENT_NODE and ATTRIBUTE_NODE returns the name of the node. For
other node types return as follows:
TEXT_NODE => "#text", CDATA_SECTION_NODE => "#cdata-section",
COMMENT_NODE => "#comment", DOCUMENT_NODE => "#document",
PROCESSING_INSTRUCTION_NODE => target of this node
Not in DOM spec.
view all matches for this distribution
view release on metacpan or search on metacpan
t/builtin.t view on Meta::CPAN
#------------------------------------------------------------------------
# CDATA
$pkg = 'XML::Schema::Type::CDATA';
my $cdata = $pkg->new();
ok( $cdata );
match( $cdata->name(), 'CDATA' );
$item = $cdata->instance(" \tThe cat\n\tsat on\r\tthe mat\n\t ");
ok( $item );
match( $item->{ value }, " The cat sat on the mat ");
#------------------------------------------------------------------------
# token
view all matches for this distribution
view release on metacpan or search on metacpan
fix.
- t/11tag-in-different-locations.t
- Added a regression test against bug:
http://rt.cpan.org/Ticket/Display.html?id=2322
- Seems to already have been fixed.
- t/12missing-element-has-o-as-cdata.t
0.95 2002-04-09
[ Undocumented changelog. ]
0.93 2001-06-14
view all matches for this distribution
view release on metacpan or search on metacpan
t/1_XMLin.t view on Meta::CPAN
is_deeply($opt, $target, 'keeproot option works');
# confirm that CDATA sections parse correctly
$xml = q{<opt><cdata><![CDATA[<greeting>Hello, world!</greeting>]]></cdata></opt>};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, {
'cdata' => '<greeting>Hello, world!</greeting>'
}, 'CDATA section parsed correctly');
$xml = q{<opt><x><![CDATA[<y>one</y>]]><![CDATA[<y>two</y>]]></x></opt>};
$opt = XMLin($xml, @cont_key);
is_deeply($opt, {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Smart.pm view on Meta::CPAN
#############
# SET_CDATA #
#############
sub set_cdata {
my $this = shift ;
$this->set_node_type('cdata',@_) ;
}
##############
# SET_BINARY #
##############
lib/XML/Smart.pm view on Meta::CPAN
Return a copy of the XML::Smart object (pointing to the base).
** This is good when you want to keep 2 versions of the same XML tree in the memory,
since one object can't change the tree of the other!
B<WARNING:> set_node(), set_cdata() and set_binary() changes are not persistant over copy -
Once you create a second copy these states are lost.
b<warning:> do not copy after apply_dtd() unless you have checked for dtd errors.
=head2 cut_root()
lib/XML/Smart.pm view on Meta::CPAN
=head2 set_auto
Define the key to be handled automatically. Soo, data() will define automatically if it's a node, content or attribute.
I<** This method is useful to remove set_node(), set_cdata() and set_binary() changes.>
=head2 set_auto_node
Define the key as a node, and data() will define automatically if it's CDATA or BINARY.
I<** This method is useful to remove set_cdata() and set_binary() changes.>
=head2 set_binary(BOOL)
Define the node as a BINARY content when TRUE, or force to B<not> handle it as a BINARY on FALSE.
lib/XML/Smart.pm view on Meta::CPAN
Original content of foo (the base64 data):
<h1>test \x03</h1>
=head2 set_cdata(BOOL)
Define the node as CDATA when TRUE, or force to B<not> handle it as CDATA on FALSE.
Example of CDATA node:
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Spice.pm view on Meta::CPAN
my ($val) = @_;
$val =~ s/'/'/g;
return $val;
}
sub _escape_cdata {
my ($val) = @_;
$val =~ s/&/&/g;
$val =~ s/</</g;
$val =~ s/>/>/g;
$val =~ s/"/"/g;
lib/XML/Spice.pm view on Meta::CPAN
$xml .= $thing->_xml;
}
else {
next if $thing eq "";
$xml .= _escape_cdata($thing);
}
}
return $xml;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Stream.pm view on Meta::CPAN
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
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/TMX/Reader.pm view on Meta::CPAN
for my $v (@$c) {
if ($v->[0] eq "-prop") {
push @{$tuv->{$v->[0]}{$v->[1]}}, $v->[2]
} elsif ($v->[0] eq "-note") {
push @{$tuv->{$v->[0]}}, $v->[1]
} elsif ($v->[0] eq "-cdata") {
$tuv->{-iscdata} = 1;
$tuv->{-seg} = $v->[1];
} else {
$tuv->{-seg} = $v->[0];
}
}
[ $v{lang} || $v{'xml:lang'} || "_" => $tuv ]
},
prop => sub { ["-prop", $v{type} || "_", $c] },
note => sub { ["-note" , $c] },
seg => sub {
return ($v{iscdata}) ? [ -cdata => $c ] : [ $c ]
},
-cdata => sub {
father->{'iscdata'} = 1; $c },
hi => sub { $self->{ignore_markup}?$c:toxml },
ph => sub { $self->{ignore_markup}?$c:toxml },
);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Tape.pm view on Meta::CPAN
$this->{parser} = new XML::Parser( Handlers => {
Start => sub { $this->handle_start(@_); },
Char => sub { $this->handle_char(@_); },
Comment => sub { $this->handle_comment(@_); },
Proc => sub { $this->handle_proc(@_); },
CdataStart => sub { $this->handle_cdata_start(@_); },
CdataEnd => sub { $this->handle_cdata_end(@_); },
End => sub { $this->handle_end(@_); },
Final => sub { $this->handle_final(@_); },
});
$this->{parsernb} = $this->{parser}->parse_start();
lib/XML/Tape.pm view on Meta::CPAN
elsif ($this->{nav}->{in_record}) {
$this->{curr}->addRecordXML($xp->original_string);
}
}
sub handle_cdata_start {
my ($this, $xp) = @_;
if (0) {}
elsif ($this->{nav}->{in_tape_admin}) {
$this->{curr}->addAdminXML($xp->original_string);
lib/XML/Tape.pm view on Meta::CPAN
elsif ($this->{nav}->{in_record}) {
$this->{curr}->addRecordXML($xp->original_string);
}
}
sub handle_cdata_end {
my ($this, $xp) = @_;
if (0) {}
elsif ($this->{nav}->{in_tape_admin}) {
$this->{curr}->addAdminXML($xp->original_string);
lib/XML/Tape.pm view on Meta::CPAN
$this->{parser} = new XML::Parser( Handlers => {
Start => sub { $this->handle_start(@_); },
Char => sub { $this->handle_char(@_); },
Comment => sub { $this->handle_comment(@_); },
Proc => sub { $this->handle_proc(@_); },
CdataStart => sub { $this->handle_cdata_start(@_); },
CdataEnd => sub { $this->handle_cdata_end(@_); },
End => sub { $this->handle_end(@_); },
Final => sub { $this->handle_final(@_); },
});
$this->{parsernb} = $this->{parser}->parse_start();
lib/XML/Tape.pm view on Meta::CPAN
elsif ($this->{nav}->{in_record}) {
$this->{curr}->addRecordXML($xp->original_string);
}
}
sub handle_cdata_start {
my ($this, $xp) = @_;
if (0) {}
elsif ($this->{nav}->{in_tape_admin}) {
$this->{curr}->addAdminXML($xp->original_string);
lib/XML/Tape.pm view on Meta::CPAN
elsif ($this->{nav}->{in_record}) {
$this->{curr}->addRecordXML($xp->original_string);
}
}
sub handle_cdata_end {
my ($this, $xp) = @_;
if (0) {}
elsif ($this->{nav}->{in_tape_admin}) {
$this->{curr}->addAdminXML($xp->original_string);
view all matches for this distribution
view release on metacpan or search on metacpan
t/02-oddballs.t
t/two-docs.xml
t/doc-and-a-bit.xml
t/text-only.xml
t/03-attribs.t
t/04-cdata.t
t/05-fatal_declarations.t
t/06-entities.t
t/99-w3c-not-wf.t
t/w3c/not-wf/ext-sa/001.ent
t/w3c/not-wf/ext-sa/001.xml
t/51-localize-filehandle.t
t/localize-filehandles.xml
ARTISTIC.txt
GPL2.txt
t/52-bugfix-namecharacters.t
t/53-bugfix-cdata-in-attrib.t
t/cdata-in-attrib.xml
t/54-bugfix-bom.t
t/bom-UTF-16-BE.xml
t/bom-UTF-16-LE.xml
t/bom-UTF-8.xml
t/bom-UTF-32-BE.xml
view all matches for this distribution
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
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