view release on metacpan or search on metacpan
dtd2html.pl view on Meta::CPAN
sub end_element {}
sub characters {}
sub processing_instruction {}
sub ignorable_whitespace {}
sub comment {}
sub start_cdata {}
sub end_cdata {}
sub start_entity {}
sub end_entity {}
sub xml_decl {}
sub start_dtd {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
=item * on_end_element
=item * on_characters
=item * on_cdata
=back
XML::Handler::ExtOn put all B<cdata> characters into a single event C<on_cdata>.
It compliant XML namespaces (http://www.w3.org/TR/REC-xml-names/), by support
I<default namespace> and I<namespace scoping>.
XML::Handler::ExtOn provide methods for create XML, such as C<mk_element>, C<mk_cdata> ...
=head1 FUNCTIONS
=cut
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
use base 'XML::SAX::Base';
use vars qw( $AUTOLOAD);
$XML::Handler::ExtOn::VERSION = '0.06';
### install get/set accessors for this object.
for my $key (qw/ context _objects_stack _cdata_mode _cdata_characters/) {
no strict 'refs';
*{ __PACKAGE__ . "::$key" } = sub {
my $self = shift;
$self->{___EXT_on_attrs}->{$key} = $_[0] if @_;
return $self->{___EXT_on_attrs}->{$key};
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
sub new {
my $class = shift;
my $self = &XML::SAX::Base::new( $class, @_, );
$self->_objects_stack( [] );
$self->_cdata_mode(0);
my $buf;
$self->_cdata_characters( \$buf ); #setup cdata buffer
my $doc_context = new XML::Handler::ExtOn::Context::;
$self->context($doc_context);
return $self;
}
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
For example:
sub on_start_element {
my $self = shift;
my $elem = shift;
$elem->add_content( $self->mk_cdata("test"));
return $elem
}
...
return [ $elem, ,$self->mk_element("after_start_elem") ]
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
sub on_characters {
my ( $self, $elem, $str ) = @_;
return $str;
}
=head2 on_cdata ( $current_element, $data )
Must return string for write to stream
sub on_cdata {
my ( $self, $elem, $str ) = @_;
return lc $str;
}
=cut
sub on_cdata {
my ( $self, $elem, $str ) = @_;
return $str;
}
#set flag for cdata content
sub start_cdata {
my $self = shift;
$self->_cdata_mode(1);
return;
}
#set flag to end cdata
sub end_cdata {
my $self = shift;
if ( my $elem = $self->current_element
and defined( my $cdata_buf = ${ $self->_cdata_characters } ) )
{
if ( defined( my $data = $self->on_cdata( $elem, $cdata_buf ) ) ) {
$self->SUPER::start_cdata;
$self->SUPER::characters( { Data => $data } );
$self->SUPER::end_cdata;
}
}
#after all clear cd_data_buffer and reset cd_data mode flag
my $new_buf;
$self->_cdata_characters( \$new_buf );
$self->_cdata_mode(0);
return;
}
sub characters {
my $self = shift;
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
return
# #warn "characters without element"
}
#for cdata section collect characters in buffer
if ( $self->_cdata_mode ) {
${ $self->_cdata_characters } .= $data->{Data};
return;
}
#collect chars fo current element
if (
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
}
);
return $parser;
}
=head2 mk_cdata $string | \$string
return command for insert cdata to stream
=cut
sub mk_cdata {
my $self = shift;
my $string = shift;
return { type => 'CDATA', data => ref($string) ? $string : \$string };
}
lib/XML/Handler/ExtOn.pm view on Meta::CPAN
}
$self->end_element($comm);
}
elsif ( ref($comm) eq 'HASH' and exists $comm->{type} ) {
if ( $comm->{type} eq 'CDATA' ) {
$self->start_cdata;
$self->characters( { Data => ${ $comm->{data} } } );
$self->end_cdata;
}
elsif ( $comm->{type} eq 'CHARACTERS' ) {
$self->characters( { Data => ${ $comm->{data} } } );
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
YAWriter.pm view on Meta::CPAN
my ($self, $string) = @_;
return &{$self->{EscSub}}($string, $self->{'Escape'});
}
sub start_cdata {
my ($self, $cdata) = @_;
$self->{'InCDATA'} = 1;
$self->print(undef, '<![CDATA[', undef);
}
sub end_cdata {
my ($self, $cdata) = @_;
$self->{'InCDATA'} = 0;
$self->print(undef, ']]>', undef);
}
sub print {
view all matches for this distribution
view release on metacpan or search on metacpan
$XML::Hash::LX::X2H{trim} = 0; # don't trim whitespace
$XML::Hash::LX::X2H{attr} = '+'; # make attributes as keys with prefix '+';
$XML::Hash::LX::X2H{text} = '~'; # make text node as key '~';
#$XML::Hash::LX::X2H{join} = ' '; # join all whitespaces with ' ';
#$XML::Hash::LX::X2H{join} = undef;# don't join text nodes
$XML::Hash::LX::X2H{cdata} = '#'; # separate cdata sections from common values and save it under key '#';
$XML::Hash::LX::X2H{comm} = '//'; # keep comments and store under key '//';
# array cast
$XML::Hash::LX::X2A{nest} = 1; # node with name 'nest' should be always stored as array
#$XML::Hash::LX::X2A = 1; # all nodes should be always stored as array
first
<v>a</v>
mid
<!-- something commented -->
<v at="a">b</v>
<vv><![CDATA[ cdata <<>> content ]]></vv>
last
</nest>
</root>},
attr => '.', # locally override attr to be prefixed with '.'
;
# hash to xml options
$XML::Hash::LX::H2X{trim} = 1; # ignore whitespace
$XML::Hash::LX::H2X{attr} = '+'; # keys, starting from '+' are attributes
$XML::Hash::LX::H2X{text} = '~'; # key '~' is text node
$XML::Hash::LX::H2X{cdata} = '#'; # key '#' is CDATA node
$XML::Hash::LX::H2X{comm} = '//'; # key '//' is comment node
# scalarref is treated as raw xml
$hash->{root}{inject} = \('<rawnode attr="zzz" />');
# refref is treated as XML::LibXML elements, and will be cloned and inserted
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Hash/XS.pm view on Meta::CPAN
require XSLoader;
XSLoader::load('XML::Hash::XS', $VERSION);
use vars qw($method $output $root $version $encoding $utf8 $indent $canonical
$use_attr $content $xml_decl $doc $max_depth $attr $text $trim $cdata
$comm $buf_size $keep_root $force_array $force_content $merge_text
$suppress_empty
);
# 'NATIVE' or 'LX'
lib/XML/Hash/XS.pm view on Meta::CPAN
$suppress_empty = 0;
# XML::Hash::LX options
$attr = '-';
$text = '#text';
$cdata = undef;
$comm = undef;
1;
__END__
=head1 NAME
lib/XML/Hash/XS.pm view on Meta::CPAN
if method is 'LX' then conversion result is the same as using L<XML::Hash::LX> library
Note: for 'LX' method following additional options are available:
attr
cdata
text
comm
=back
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/LibXML/LazyBuilder.pm view on Meta::CPAN
# This is a map of all the DOM level 3 node names for
# non-element/attribute nodes. Note how there is no provision for
# processing instructions.
my %NODES = (
'#cdata-section' => 1,
'#comment' => 1,
'#document' => 1,
'#document-fragment' => 1,
'#text' => 1,
);
view all matches for this distribution
view release on metacpan or search on metacpan
doap.ttl
t/01basic.t
t/02stripws.t
t/03indent.t
t/04print.t
t/61cdata.t
Copyright: Copyright 2014 Toby Inkster.
License: GPL-1.0+ or Artistic-1.0
Files: CONTRIBUTING
INSTALL
view all matches for this distribution
view release on metacpan or search on metacpan
t/10XMLin.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
no_blanks => XML_PARSE_NOBLANKS,
expand_xinclude => XML_PARSE_XINCLUDE,
xinclude => XML_PARSE_XINCLUDE,
no_network => XML_PARSE_NONET,
clean_namespaces => XML_PARSE_NSCLEAN,
no_cdata => XML_PARSE_NOCDATA,
no_xinclude_nodes => XML_PARSE_NOXINCNODE,
old10 => XML_PARSE_OLD10,
no_base_fix => XML_PARSE_NOBASEFIX,
huge => XML_PARSE_HUGE,
oldsax => XML_PARSE_OLDSAX,
}
$flags |= 64 if $opts->{suppress_warnings};
$flags |= 128 if exists $opts->{pedantic_parser} ? $opts->{pedantic_parser} : $self->pedantic_parser;
$flags |= 256 if exists $opts->{no_blanks} ? $opts->{no_blanks} : !$self->keep_blanks;
$flags |= 2048 if exists $opts->{no_network} ? $opts->{no_network} : !$self->no_network;
$flags |= 16384 if $opts->{no_cdata};
$flags |= 65536 if $opts->{compact}; # compact small text nodes; no modification
# of the tree allowed afterwards
# (WILL possibly CRASH IF YOU try to MODIFY THE TREE)
$flags |= 524288 if $opts->{huge}; # relax any hardcoded limit from the parser
$flags |= 1048576 if $opts->{oldsax}; # parse using SAX2 interface from before 2.7.0
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/LibXSLT.pm view on Meta::CPAN
use XML::LibXML;
my $xslt = XML::LibXSLT->new();
my $source = XML::LibXML->load_xml(location => 'foo.xml');
my $style_doc = XML::LibXML->load_xml(location=>'bar.xsl', no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
lib/XML/LibXSLT.pm view on Meta::CPAN
invalid, an exception will be thrown, so wrap the call to
parse_stylesheet in an eval{} block to trap this.
IMPORTANT: C<$stylesheet_doc> should not contain CDATA sections,
otherwise libxslt may misbehave. The best way to assure this is to
load the stylesheet with no_cdata flag, e.g.
my $stylesheet_doc = XML::LibXML->load_xml(location=>"some.xsl", no_cdata=>1);
=item parse_stylesheet_file($filename)
Exactly the same as the above, but parses the given filename directly.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Liberal/Remedy/NestedCDATA.pm view on Meta::CPAN
my($driver, $error, $xml_ref) = @_;
return 0 if $error->message !~ /^parser error : Opening and ending tag mismatch:/;
while ($$xml_ref =~ /(?<= <!\[CDATA\[ ) (.*? \]\]> )/xmsg) {
my ($cdata, $start, $end) = ($1, $-[1], $+[1]);
next if $cdata !~ /<!\[CDATA\[/;
my $escaped = encode_entities($cdata, '<>&');
substr($$xml_ref, $start, $end - $start) = "]]>$escaped<![CDATA[";
return 1;
}
return 0;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Test/XML/Loy.pm view on Meta::CPAN
$desc
);
};
# Test for exact pcdata match
sub text_is {
my ($self, $selector, $value, $desc) = @_;
return $self->_test(
'is',
$self->_text($selector),
lib/Test/XML/Loy.pm view on Meta::CPAN
_desc($desc, qq{exact match for selector "$selector"})
);
};
# Test for pcdata mismatch
sub text_isnt {
my ($self, $selector, $value, $desc) = @_;
return $self->_test(
'isnt',
$self->_text($selector),
lib/Test/XML/Loy.pm view on Meta::CPAN
_desc($desc, qq{no match for selector "$selector"})
);
};
# Test for pcdata similarity
sub text_like {
my ($self, $selector, $regex, $desc) = @_;
return $self->_test(
'like',
$self->_text($selector),
lib/Test/XML/Loy.pm view on Meta::CPAN
_desc($desc, qq{similar match for selector "$selector"})
);
};
# Test for pcdata dissimilarity
sub text_unlike {
my ($self, $selector, $regex, $desc) = @_;
return $self->_test(
'unlike',
$self->_text($selector),
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/MinWriter.pm view on Meta::CPAN
sub startTag { my $self = shift; $self->flush_pyx; $self->SUPER::startTag(@_); }
sub emptyTag { my $self = shift; $self->flush_pyx; $self->SUPER::emptyTag(@_); }
sub endTag { my $self = shift; $self->flush_pyx; $self->SUPER::endTag(@_); }
sub characters { my $self = shift; $self->flush_pyx; $self->SUPER::characters(@_); }
sub raw { my $self = shift; $self->flush_pyx; $self->SUPER::raw(@_); }
sub cdata { my $self = shift; $self->flush_pyx; $self->SUPER::cdata(@_); }
sub dataElement { my $self = shift; $self->flush_pyx; $self->SUPER::dataElement(@_); }
sub end { my $self = shift; $self->flush_pyx; $self->SUPER::end(@_); }
sub write_pyx {
my $self = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Mini/Document.pm view on Meta::CPAN
my $unaryName = $2;
my $unaryAttribs = $3;
my $headerName = $4;
my $headerAttribs= $5;
my $comment = $6;
my $cdata = $7;
my $doctype = $8;
my $doctypeCont = $9;
my $entityName = $10;
my $entityCont = $12;
my $plainText = $13;
lib/XML/Mini/Document.pm view on Meta::CPAN
my $newElement = XML::Mini::Element::Header->new($headerName);
$self->_extractAttributesFromString($newElement, $headerAttribs) if ($headerAttribs);
$parentElement->appendChild($newElement);
} elsif (defined $comment) {
$parentElement->comment($comment);
} elsif (defined $cdata) {
my $newElement = XML::Mini::Element::CData->new($cdata);
$parentElement->appendChild($newElement);
} elsif ($doctype || defined $doctypeCont) {
my $newElement = XML::Mini::Element::DocType->new($doctype);
$parentElement->appendChild($newElement);
if ($doctypeCont)
lib/XML/Mini/Document.pm view on Meta::CPAN
{
# Check which string matched.'
my $uname = $7;
my $comment = $6;
my $cdata = $10;
my $doctypedef = $11;
if ($12)
{
if ($doctypedef)
{
lib/XML/Mini/Document.pm view on Meta::CPAN
} elsif (defined $comment) {
#my $newElement = XML::Mini::Element::Comment->new('!--');
#$newElement->createNode($comment);
$parentElement->comment($comment);
} elsif (defined $cdata) {
my $newElement = XML::Mini::Element::CData->new($cdata);
$parentElement->appendChild($newElement);
} elsif (defined $doctypedef) {
my $newElement = XML::Mini::Element::DocType->new($11);
$parentElement->appendChild($newElement);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Minifier.pm view on Meta::CPAN
#Â A. If we have <name> </name> we should keep it anyway (unless forced with argument)
# B. If we have </name> </person> we should *maybe* remove (in this case parent node contains more than one child node : text node + element node)
# C. If we have <person> <name> we should *maybe* remove it (in this case parent node contains more than one child node : text node + element node)
# D. If we have </person> <person> we should *maybe* remove it (in this case parent node contains more than one child node : text node + element node)
#Â B, C, D : remove... unless explicitely declared in DTD as potential #PCDATA container OR unless it contains something...
# *something* is a comment (not removed), some other text not empty, some cdata.
# Imagine </name> <!-- comment --> some text </person> then we don't want to remove spaces in the first text node
# Same with </name> <!-- comment --> </person>
# But if comments are removed then the latter piece of code will become </name></person>
my $empty = 1;
lib/XML/Minifier.pm view on Meta::CPAN
}
if($child->nodeType eq XML_COMMENT_NODE and $opt{keep_comments}) {
$empty = 0;
last;
}
if($child->nodeType eq XML_CDATA_SECTION_NODE and $opt{keep_cdata}) {
$empty = 0;
last;
}
if($child->nodeType eq XML_PI_NODE and $opt{keep_pi}) {
$empty = 0;
lib/XML/Minifier.pm view on Meta::CPAN
} elsif($child->nodeType eq XML_COMMENT_NODE) {
#Â Configurable with keep_comments
my $com = $doc->createComment($child->getData());
$opt{keep_comments} and $outnode->addChild($com);
} elsif($child->nodeType eq XML_CDATA_SECTION_NODE) {
#Â Configurable with keep_cdata
#my $cdata = $child->cloneNode(1);
my $cdata = $doc->createCDATASection($child->getData());
$opt{keep_cdata} and $outnode->addChild($cdata);
} elsif($child->nodeType eq XML_PI_NODE) {
#Â Configurable with keep_pi
#my $pi = $child->cloneNode(1);
my $pi = $doc->createPI($child->nodeName, $child->getData());
$opt{keep_pi} and $outnode->addChild($pi);
lib/XML/Minifier.pm view on Meta::CPAN
In addition, the minifier will drop every blanks between the first level children.
What you can find between first level children is not supposed to be meaningful data then we we can safely remove formatting here.
For instance we can remove a carriage return between prolog and a processing instruction (or even inside a DTD).
In addition again, the minifier will I<smartly> remove blanks between tags. By I<smart> I mean that it will not remove blanks if we are in a leaf (more chances to be meaningful blanks) or if the node contains something that will persist (a I<not remo...
If there is no DTD (very often), we are blind and simply use the approach I just described above (keep blanks in leafs, remove blanks in nodes if all siblings contains only blanks).
Everything listed above is the default and should be perceived as almost lossyless minification in term of semantic (for humans).
lib/XML/Minifier.pm view on Meta::CPAN
A comment is something like :
<!-- comment -->
=item B<keep_cdata>
Keep cdata, by default they are removed.
A CDATA is something like :
<![CDATA[ my cdata ]]>
=item B<keep_pi>
Keep processing instructions.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Minify.pm view on Meta::CPAN
#Â A. If we have <name> </name> we should keep it anyway (unless forced with argument)
# B. If we have </name> </person> we should *maybe* remove (in this case parent node contains more than one child node : text node + element node)
# C. If we have <person> <name> we should *maybe* remove it (in this case parent node contains more than one child node : text node + element node)
# D. If we have </person> <person> we should *maybe* remove it (in this case parent node contains more than one child node : text node + element node)
#Â B, C, D : remove... unless explicitely declared in DTD as potential #PCDATA container OR unless it contains something...
# *something* is a comment (not removed), some other text not empty, some cdata.
# Imagine </name> <!-- comment --> some text </person> then we don't want to remove spaces in the first text node
# Same with </name> <!-- comment --> </person>
# But if comments are removed then the latter piece of code will become </name></person>
my $empty = 1;
lib/XML/Minify.pm view on Meta::CPAN
}
if($child->nodeType eq XML_COMMENT_NODE and $opt{keep_comments}) {
$empty = 0;
last;
}
if($child->nodeType eq XML_CDATA_SECTION_NODE and $opt{keep_cdata}) {
$empty = 0;
last;
}
if($child->nodeType eq XML_PI_NODE and $opt{keep_pi}) {
$empty = 0;
lib/XML/Minify.pm view on Meta::CPAN
} elsif($child->nodeType eq XML_COMMENT_NODE) {
#Â Configurable with keep_comments
my $com = $doc->createComment($child->getData());
$opt{keep_comments} and $outnode->addChild($com);
} elsif($child->nodeType eq XML_CDATA_SECTION_NODE) {
#Â Configurable with keep_cdata
#my $cdata = $child->cloneNode(1);
my $cdata = $doc->createCDATASection($child->getData());
$opt{keep_cdata} and $outnode->addChild($cdata);
} elsif($child->nodeType eq XML_PI_NODE) {
#Â Configurable with keep_pi
#my $pi = $child->cloneNode(1);
my $pi = $doc->createPI($child->nodeName, $child->getData());
$opt{keep_pi} and $outnode->addChild($pi);
lib/XML/Minify.pm view on Meta::CPAN
In addition, the minifier will drop every blanks between the first level children.
What you can find between first level children is not supposed to be meaningful data then we we can safely remove formatting here.
For instance we can remove a carriage return between prolog and a processing instruction (or even inside a DTD).
In addition again, the minifier will I<smartly> remove blanks between tags. By I<smart> I mean that it will not remove blanks if we are in a leaf (more chances to be meaningful blanks) or if the node contains something that will persist (a I<not remo...
If there is no DTD (very often), we are blind and simply use the approach I just described above (keep blanks in leafs, remove blanks in nodes if all siblings contains only blanks).
Everything listed above is the default and should be perceived as almost lossyless minification in term of semantic (for humans).
lib/XML/Minify.pm view on Meta::CPAN
A comment is something like :
<!-- comment -->
=item B<keep_cdata>
Keep cdata, by default they are removed.
A CDATA is something like :
<![CDATA[ my cdata ]]>
=item B<keep_pi>
Keep processing instructions.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/NewsML_G2/Inline_CData.pm view on Meta::CPAN
1;
__END__
=head1 NAME
XML::NewsML_G2::Inline_CData - inline cdata specification
=head1 SYNOPSIS
my $data = XML::NewsML_G2::Inline_CData->new
(mimetype => 'text/xml',
view all matches for this distribution
view release on metacpan or search on metacpan
ParseDTD.pm view on Meta::CPAN
for($type) {
#/^ID(REF)?$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = \&XML::ParseDTD::_check_id; last; };
/^ID(REF)?$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = ['ID', '^[A-Za-z_]{1}[A-Za-z0-9_:.-]*$']; last; };
#/^IDREFS$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = \&XML::ParseDTD::_check_idrefs; last; };
/^IDREFS$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = ['IDREFS', '^[A-Za-z_]{1}[A-Za-z0-9_:. -]*$']; last; };
#/^CDATA$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = \&XML::ParseDTD::_check_cdata; last; };
/^CDATA$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = ['CDATA', '.*']; last; };
#/^PCDATA$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = \&XML::ParseDTD::_check_pcdata; last; };
/^PCDATA$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = ['PCDATA', '.*']; last; };
#/^NMTOKEN$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = \&XML::ParseDTD::_check_nmtoken; last; };
/^NMTOKEN$/ && do { $pdtd{'Attr'}->{$elem}->{$attr} = ['NMTOKEN', '^[A-Za-z0-9_:.-]{1}\S*$']; last; };
/^\((.*)\)$/s && do {
$_ = $1;
view all matches for this distribution
view release on metacpan or search on metacpan
t/00use.t
t/01source.t
t/02maildemo.t
t/03rdf.t
t/04ppd.t
t/05cdata.t
t/basic.xml
t/cdata.xml
t/DBI.ppd
t/mail.xml
t/uploads.rdf
examples/DBI.ppd
examples/ppd.pl
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Parser/Lite/Tree.pm view on Meta::CPAN
$self->{__parser} = new XML::Parser::LiteCopy
Handlers => {
Start => sub { $self->_start_tag(@_); },
Char => sub { $self->_do_char(@_); },
CData => sub { $self->_do_cdata(@_); },
End => sub { $self->_end_tag(@_); },
Comment => sub { $self->_do_comment(@_); },
PI => sub { $self->_do_pi(@_); },
Doctype => sub { $self->_do_doctype(@_); },
};
lib/XML/Parser/Lite/Tree.pm view on Meta::CPAN
push @{$self->{tag_stack}->[-1]->{children}}, $new_tag;
}
1;
}
sub _do_cdata {
my $self = shift;
shift;
for my $content(@_){
my $new_tag = {
'type' => 'cdata',
'content' => $content,
};
push @{$self->{tag_stack}->[-1]->{children}}, $new_tag;
}
view all matches for this distribution
view release on metacpan or search on metacpan
first
<v>a</v>
mid
<!-- something commented -->
<v at="a">b</v>
<vv><![CDATA[ cdata <<>> content ]]></vv>
last
</nest>
</root>},
);
print +Dumper $hash;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Parser/Wrapper.pm view on Meta::CPAN
=head3 pretty
If pretty is a true value, then whitespace is added to the output
to make it more human-readable.
=head3 cdata
If cdata is defined, any text nodes with length greater than
cdata are output as a CDATA section, unless it contains "]]>", in
which case the text is XML escaped.
Aliases: toXml()
=head3 decl
lib/XML/Parser/Wrapper.pm view on Meta::CPAN
}
if ($self->is_text) {
my $text = $self->text;
if (defined $options->{cdata}) {
if (length($text) >= $options->{cdata}) {
unless (index($text, ']]>') > -1) {
return '<![CDATA[' . $text . ']]>';
}
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
YahooRESTGeocode.pm view on Meta::CPAN
reverse (@data);
return (\@data);
}
## extract_pcdata #################################
sub extract_pcdata {
my $data = shift();
my %out = ();
foreach (@{$data}){
foreach my $f (@_){
if (($_->{'_name'} eq $f) && ($_->{'_data'} !~/^$/)){
YahooRESTGeocode.pm view on Meta::CPAN
sub End {
my ($expat, $element) = @_;
if (exists($node_tree{$element})){
my $data = extract_pcdata(gather_data($expat, $element), @{$node_tree{$element}});
push (@{$expat->{'Lists'}->{'DATA'}->{$element}}, $data);
#if the user defined some callback to execute, do that
if (exists($expat->{'_YahooREST_callbacks'}->{$element})){
&{$expat->{'_YahooREST_callbacks'}->{$element}}($data);
view all matches for this distribution
view release on metacpan or search on metacpan
the default handler.
- For lwp_ext_ent_handler, use URI::URL instead of URI so that old
5.004 installations will work with it.
2.25 Fri Jul 23 06:23:43 EDT 1999
- Now using Version 1990709 of expat. No local patches.
- Numerous people reported a SEGV problem when running t/cdata
on various platforms and versions of perl. The problem was
introduced with the setHandlers change. In some cases an
un-initialized value was being returned.
- Added an additional external entity handler, lwp_ext_ent_handler,
that deals with general URIs. It is installed instead of the
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/Quick.pm view on Meta::CPAN
use base qw(Exporter);
our @EXPORT = qw(xml);
# cdata escaping
sub _escape($) {
my ($cdata) = @_;
$cdata =~ s/&/&/g;
$cdata =~ s/</</g;
$cdata =~ s/>/>/g;
$cdata =~ s/"/"/g;
$cdata =~ s/([^\x20-\x7E])/'&#' . ord($1) . ';'/ge;
return $cdata;
};
sub xml {
my ($data, $opts) = @_;
lib/XML/Quick.pm view on Meta::CPAN
$xml = $opts->{escape} ? _escape($data) : $data;
}
# dig down into hashes
else {
# move attrs/cdata into opts as necessary
if(exists $data->{_attrs}) {
$opts->{attrs} = $data->{_attrs} if not exists $opts->{attrs};
}
if(exists $data->{_cdata}) {
$opts->{cdata} = $data->{_cdata} if not exists $opts->{cdata};
}
# loop over the keys
for my $key (keys %{$data}) {
# skip meta
lib/XML/Quick.pm view on Meta::CPAN
# hash
elsif(reftype $data->{$key} eq 'HASH') {
$xml .= xml($data->{$key}, { root => $key,
attrs => $data->{$key}->{_attrs} || {},
cdata => $data->{$key}->{_cdata} || '' })
}
# array
elsif(reftype $data->{$key} eq 'ARRAY') {
$xml .= xml($_, { root => $key }) for @{$data->{$key}};
lib/XML/Quick.pm view on Meta::CPAN
$wrap .= " $key='$val'";
}
}
# character data
if($opts->{cdata}) {
$xml = ($opts->{escape} ? _escape($opts->{cdata}) : $opts->{cdata}) . $xml;
}
# if there's no content, then close it up right now
if($xml eq '') {
$wrap .= '/>';
lib/XML/Quick.pm view on Meta::CPAN
});
# produces: <tag foo='bar'/>
Of course, you're probably going to want to include a value or other tags
inside this tag. For a value, use the C<_cdata> key:
xml({
'tag' => {
'_attrs' => {
'foo' => 'bar'
},
'_cdata' => 'value'
}
});
# produces: <tag foo='bar'>value</tag>
lib/XML/Quick.pm view on Meta::CPAN
Used in conjuction with the C<root> option to add attributes to the root tag.
xml({ tag => 'value' }, { root => 'wrap', attrs => { style => 'shiny' }});
# produces: <wrap style='shiny'><tag>value</tag></wrap>
=item * cdata
Used in conjunction with the C<root> option to add character data to the root
tag.
xml({ tag => 'value' }, { root => 'wrap', cdata => 'just along for the ride' });
# produces: <wrap>just along for the ride<tag>value</tag></wrap>
You probably don't need to use this. If you just want to create a basic tag
from nothing do this:
xml({ tag => 'value' });
Rather than this:
xml('', { root => 'tag', cdata => 'value' });
You almost certainly don't want to add character data to a root tag with nested
tags inside. See L<BUGS AND LIMITATIONS> for more details.
=item * escape
lib/XML/Quick.pm view on Meta::CPAN
the hash. This generally won't be a problem as the vast majority of XML-based
datatypes don't care about order. I don't recommend you use this module to
create XML when order is important (eg XHTML, XSL, etc).
Things are even more hairy when including character data alongside tags via the
C<cdata> or C<_cdata> options. The C<cdata> options only really exist to allow
attributes and values to be specified for a single tag. The rich support
necessary to support multiple character data sections interspersed alongside
tags is entirely outside the scope of what the module is designed for.
There are probably bugs. This kind of thing is an inexact science. Feedback
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/RSS/Parser/Util.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.
lib/XML/RSS/Parser/Util.pm view on Meta::CPAN
will add an XML 1.0 standard declaration to the returned
XML. The third parameter (also optional) parameter defines
the encoding to be used in the declaration. The default is
'utf-8'.
=item encode_xml ($string[, $nocdata])
XML encodes any characters in the string that are required
to be represented as entities. This method will attempt to
identify anything that looks like markup and CDATA encodes
it. This can optional be turned off by passing a second
view all matches for this distribution
view release on metacpan or search on metacpan
keep-out/rejects/append.pl view on Meta::CPAN
# and has been completely unused. Our guess was that it introduced to later
# serve in refactoring the module and was never used. It was not moved to
# this file, to possibly be used for future reference.
sub append {
my($self, $inside, $cdata) = @_;
my $ns = $self->namespace($self->current_element);
# If it's in the default RSS 1.0 namespace
if ($ns eq 'http://purl.org/rss/1.0/') {
#$self->{'items'}->[$self->{num_items}-1]->{$self->current_element} .= $cdata;
$inside->{$self->current_element} .= $cdata;
}
# If it's in another namespace
#$self->{'items'}->[$self->{num_items}-1]->{$ns}->{$self->current_element} .= $cdata;
$inside->{$ns}->{$self->current_element} .= $cdata;
# If it's in a module namespace, provide a friendlier prefix duplicate
$self->{modules}->{$ns} and $inside->{$self->{modules}->{$ns}}->{$self->current_element} .= $cdata;
return $inside;
}
view all matches for this distribution
view release on metacpan or search on metacpan
Registry.pm view on Meta::CPAN
print " $attrib=".'"'.$attribs->{$attrib}.'"'
}
# print closing bracket
if (scalar(@$tree) > 2) {
print ">";
# no cdata for this element
} else {
print "/>";
}
# print cdata
} elsif ($tree->[$i] eq 0) {
print $tree->[++$i];
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
BuildSAXBase.pl view on Meta::CPAN
ignorable_whitespace => [qw(ContentHandler DocumentHandler Handler)],
set_document_locator => [qw(ContentHandler DocumentHandler Handler)],
start_prefix_mapping => [qw(ContentHandler Handler)],
end_prefix_mapping => [qw(ContentHandler Handler)],
skipped_entity => [qw(ContentHandler Handler)],
start_cdata => [qw(DocumentHandler LexicalHandler Handler)],
end_cdata => [qw(DocumentHandler LexicalHandler Handler)],
comment => [qw(DocumentHandler LexicalHandler Handler)],
entity_reference => [qw(DocumentHandler Handler)],
notation_decl => [qw(DTDHandler Handler)],
unparsed_entity_decl => [qw(DTDHandler Handler)],
element_decl => [qw(DeclHandler Handler)],
BuildSAXBase.pl view on Meta::CPAN
=item * end_prefix_mapping
=item * skipped_entity
=item * start_cdata
=item * end_cdata
=item * comment
=item * entity_reference
view all matches for this distribution
view release on metacpan or search on metacpan
lib/XML/SAX/PurePerl.pm view on Meta::CPAN
my $data = $reader->data(9);
return 0 unless $data =~ /^<!\[CDATA\[/;
$reader->move_along(9);
$self->start_cdata({});
$data = $reader->data;
while (1) {
$self->parser_error("EOF looking for CDATA section end", $reader)
unless length($data);
lib/XML/SAX/PurePerl.pm view on Meta::CPAN
$self->characters({Data => $data});
$reader->move_along(length($data));
$data = $reader->data;
}
}
$self->end_cdata({});
return 1;
}
sub CharData {
my ($self, $reader) = @_;
lib/XML/SAX/PurePerl.pm view on Meta::CPAN
$self->skip_whitespace($reader);
$reader->match('=') or $self->parser_error("No '=' in Attribute", $reader);
$self->skip_whitespace($reader);
my $value = $self->AttValue($reader);
if (!$self->cdata_attrib($name)) {
$value =~ s/^\x20*//; # discard leading spaces
$value =~ s/\x20*$//; # discard trailing spaces
$value =~ s/ {1,}/ /g; # all >1 space to single space
}
lib/XML/SAX/PurePerl.pm view on Meta::CPAN
}
return;
}
sub cdata_attrib {
# TODO implement this!
return 1;
}
sub AttValue {
view all matches for this distribution