hello monks,
I have a probelm with XML::SMart parser.
This is my XML structure.
<ISSUES> <ISSUE> <ISSUE-DESC> <P nd="description"></P> <P nd="category"></P> <P nd="name"></P> <P nd="level"></P> <P nd="occurance"></P> </ISSUE-DESC> </ISSUE> </ISSUES>

Below is my code
#!/usr/bin/perl -w use strict; use XML::SMART; my $strTestString =' J&K; combine'; my $XML = XML::Smart->new(q`<?xml version="1.0" encoding="UTF-8" ?><IS +SUES><ISSUE><ISSUE-DESC><P></P></ISSUE-DESC></ISSUE></ISSUES>`, 'XML: +:Smart::Parser'); my $xmlfile = "C:/perl/xml/test.xml"; my $para={SI => 'description'}; $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[0]=$para; $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[0]->set_binary(0); $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[0]->set_cdata(1); $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[0]->content(0,"$strTestString") +; $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[1]->set_cdata(0); $XML->{ISSUES}{ISSUE}{'ISSUE-DESC'}{P}[1] = "test"; XML->save($xmlfile, nometagen => 1, forceutf8 => 1);

I have the following problems

1. When there is a text which contains the & and ; together with out any space this & is not parsed as & instead it throws error. This is the reason why i asked for a regex to add a space before ; in the string. http://perlmonks.org/?node_id=652084

2. I would be able to overcome this if the parser sets the data as CDATA. This i do it by set_cdata(1) but this is not considered atall.
So my

node always contains text and not CDATA.
Also there are some binary data in my text. this parser parse it as binary and puts it in an encoded way. But i dont want this behaviour instead i wanted them in CDATA. So i also set set_binary(0) but this is also ignored

I want CDATA only for my <P nd="description"></P> node and not any other <P>NODES. Is this possible?
I use XML::Smart v 1.6.9 and PERL 5.6.1 (this is the perl which is bundled with IBM Rational Clearcase)
Also to mention my XML encoding is UTF-8
Any help would be really appreciated

Best Regards
Karthik


In reply to CDATA probelm in XML::SMart by KarthikK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.