|
Re: Patch for XML::Writer: msg#00076lang.perl.xml
On Tue, 23 Dec 2003, Duncan Cameron wrote: > The way that you are dealing with an embedded ]]> sequence within the > data to be written as CDATA is incorrect. You cannot just escape the >, > remember that you're writing CDATA and everything is treated literally > including escape sequences when the document is parsed. > I think that the only valid thing to do is to break the data on the ]]> > sequence, close the CDATA section, write the ]]> as ordinary data > (escaping the > character), then start a new CDATA section. More conveniently (?) you can just break the CDATA section in the middle of the ]]> <!CDATA[This is a CDATA section <![CDATA[text]]]]><!CDATA[[>]]> Nice hey? See it in action below: #!/usr/bin/perl -lw use strict; use XML::Twig; use XML::Simple; undef $/; my $xml= <DATA>; my $twig= XML::Twig->new->parse( $xml); print "twig: ", $twig->root->field( 'cdata'); my $simple= XMLin( $xml); print "simple: ", $simple->{cdata}; __DATA__ <doc> <cdata><![CDATA[This is a CDATA section <![CDATA[text]]]]><![CDATA[>]]></cdata> </doc> _______________________________________________ Perl-XML mailing list Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Patch for XML::Writer, Duncan Cameron |
|---|---|
| Next by Date: | Re: Patch for XML::Writer, srinithan |
| Previous by Thread: | Re: Patch for XML::Writer, Duncan Cameron |
| Next by Thread: | Re: Patch for XML::Writer, srinithan |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |