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