XML-Compile

 view release on metacpan or  search on metacpan

lib/XML/Compile/FAQ.pod  view on Meta::CPAN

You will probably need more than one attempt to produce the correct
output... Only use this when you are sure that the receiving party
is broken.

=head3 Producing CDATA blocks (writer)

To get CDATA blocks, the solution is very close to the example in the
previous section:

   my $doc   = XML::LibXML::Document->new('1.1', 'UTF-8');
   my $cdata = $doc->createCDATASection($content);
   my $xml   = $schema->writer($type)->($doc, { field => $cdata });
   $doc->setDocumentElement($xml);

The "$content" is a Perl string, which means that it needs to be
utf8 when it is utf8.  For instance:

   use File::Slurp::Tiny;
   my $content = read_file $filename, binmode => 'utf8';
   my $cdata   = $doc->createCDATASection($content);

When using SOAP (with or without WSDL) you need to do something like
this:

   use XML::LibXML;   # for ::Document
   my $wsdl     = ...usual...

   my $doc      = XML::LibXML::Document->new('1.0', 'UTF-8');
   my %data     = (
      _doc     => $doc,

t/21types.t  view on Meta::CPAN

###

test_rw($schema, testA => "<testA>abc</testA>", 'abc'); 

my $r1 = reader_create $schema, "CDATA reader" => "{$TestNS}testA";
my $cd = '<testA><![CDATA[abc]]></testA>';

my $r1a = $r1->($cd);
cmp_ok($r1a, 'eq', 'abc');

my $cdata = XML::LibXML::CDATASection->new('abc'); 
is('<![CDATA[abc]]>', $cdata->toString(1));

#XXX MO 20120815: XML::LibXML crashed on cleanup of double refs to CDATA
# object (as done in clone of test_rw).  Other XML::LibXML objects do not
# crash on this.
#test_rw($schema, testA => $cd, 'abc', $cd, $cdata);

test_rw($schema, testA => '<testA></testA>', '');



( run in 0.565 second using v1.01-cache-2.11-cpan-454fe037f31 )