Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am using XML::Excel this module to convert Excel file to XML .In Excel there are some ampersand symbol(&).While convert from Excel to XML.IN XML file There are printing like (amp;) instead of printing &

This is my code

use XML::Excel; $excel_obj = XML::Excel->new(); $excel_obj->parse_doc("file.xls", {headings => 1}); $excel_obj->print_xml("file_output.xml");

Regards,

Senthil

  • Comment on Printing & instead of & while converting Excel file to xml file
  • Download Code

Replies are listed 'Best First'.
Re: Printing & instead of & while converting Excel file to xml file
by jethro (Monsignor) on Sep 15, 2011 at 12:18 UTC

    '&' is a reserved symbol in XML, used in the same way as the backslash in perl strings. So if you want to have a real backslash in a perl string you have to use two backslashes. If you want a real ampersand in XML data you have to use '&'.

Re: Printing & instead of & while converting Excel file to xml file
by keszler (Priest) on Sep 15, 2011 at 12:27 UTC

    If you mean the ampersand is converting to "amp;" instead of "&", that's a problem. If you mean that it's not appearing as "&", that's by design

    From the XML specification at http://www.w3.org/TR/xml/#syntax:

    The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.