Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi, Thanks for the fast reply. For instance i use the following XML file:

<?xml version="1.0" encoding="UTF-8"?> <log> <logentry revision="12345"> <author>someAuthor</author> <date>2017-10-11T09:32:15.704935Z</date> <msg>This is my SVN message with characters like or &amp;.</msg> </logentry> </log>

After I execute the following script ...

use XML::Smart; open(my $fh, "<", "test.xml") or die $!; my $logString; while (<$fh>) { $logString .= $_; } my $test = XML::Smart->new($logString); $test->{log}->{logentry}[0]->{msg}->set_binary('FALSE'); print $test->data();

... I get the following result.

<?xml version="1.0" encoding="UTF-8" ?> <?meta name="GENERATOR" content="XML::Smart/1.78 Perl/5.024001 [MSWin3 +2]" ?> <log> <logentry revision="12345"> <author>someAuthor</author> <date>2017-10-11T09:32:15.704935Z</date> <msg dt:dt="binary.base64">VGhpcyBpcyBteSBTVk4gbWVzc2FnZSB3aXRoIGN +oYXJhY3RlcnMgbGlrZSDkIG9yICYu</msg> </logentry> </log>

If i call the subroutine data(decode => 1) the msg element contains the decoded message:

<msg>This is my SVN message with characters like or &.</msg>

But this output is invalid because "&" is not replaced by an escape sequence. I need an XML file with no Base64 encoding and escaped special XML characters like "&". All in one, a valid XML document without Base64 encoding. The XML parser which parses the output of the script can't handle Base64 encoding. I wonder if can solve the problem by using the subroutine set_binary('FALSE'). PS: Im using Strawberry Perl v5.24.1 on Windows Server 2012 R2 Datacenter.

In reply to Re^2: XML::Smart - undesired decoding of special XML characters by NeedForPerl
in thread XML::Smart - undesired decoding of special XML characters by NeedForPerl

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2019-11-21 13:51 GMT
    Find Nodes?
      Voting Booth?
      Strict and warnings: which comes first?

      Results (104 votes). Check out past polls.