I was using XML::Simple to make very minor edits to some proprietary XML. It works well enough, but when I use XML::Simple's XMLout to save the XML hash, it strips the CDATA tags, leaving the enclosed text in the XML output.

Before I start down another XML library that may not do what I need it to do, I thought I'd ask for suggestions. Or perhaps someone knows how to get XML::Simple to preserve the CDATA tags.

I need a simple XML parser that I can use to do a quick read in of a small XML document, make a couple of changes, and then output the XML again without stripping the CDATA tags.

p.s. In response to ikegami, I am using XML::Simple's XMLout to turn the hash from XMLin back into XML. I haven't seen a flag for getting it to re-encase the bare text. Mind you, the source only seemed to use CDATA some of the time, not all of the time.

<TABLE>
<ROW>
<SITNAME>
BS_NT_DEF_OPS_SVC_Auto_Crit
</SITNAME>
<TEXT>
<![CDATA[Critical threshold for SVC (Automatic Service not Running)]]>
</TEXT>
<AFFINITIES>
00080000000000000000000000000000#*########F
</AFFINITIES>
<PDT>
<![CDATA[*IF *VALUE NT_Services.Start_Type *EQ Automatic *AND *VALUE NT_Services.Current_State *NE Running]]>
</PDT>
<REEV_DAYS>
0
</REEV_DAYS>
<REEV_TIME>
000300
</REEV_TIME>
<AUTOSTART>
*YES
</AUTOSTART>
<ADVISE>
<![CDATA[*NONE]]>
</ADVISE>
<CMD>
<![CDATA[net start "&NT_Services.Service_Name"]]>
</CMD>
<AUTOSOPT>
YNN
</AUTOSOPT>
<DISTRIBUTION>
BL_NT_DEF,BL_NT_DEF_V
</DISTRIBUTION>
<ALERTLIST>
</ALERTLIST>
<HUB>
</HUB>
<QIBSCOPE>
E
</QIBSCOPE>
<SENDMSGQ>
*NONE
</SENDMSGQ>
<DESTNODE>
</DESTNODE>
<LOCFLAG>
</LOCFLAG>
<LSTCCSID>
en_US
</LSTCCSID>
<LSTDATE>
1080528162416000
</LSTDATE>
<LSTRELEASE>
V100
</LSTRELEASE>
<LSTUSRPRF>
u758725
</LSTUSRPRF>
<NOTIFYARGS>
</NOTIFYARGS>
<NOTIFYOPTS>
</NOTIFYOPTS>
<OBJECTLOCK>
</OBJECTLOCK>
<PRNAMES>
</PRNAMES>
<REFLEXOK>
</REFLEXOK>
<SITINFO>
<![CDATA[COUNT=2;ATOM=NTSERVICE.SRVCNAME;TFWD=Y;SEV=Fatal;TDST=0;~]]>
</SITINFO>
<SOURCE>
</SOURCE>
</ROW>
</TABLE>
For anyone interested, that is the XML output from IBM Tivoli Monitoring version 6.

In reply to Preserving CDATA Tags When Saving XML by THuG

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.