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

Hi Monks,
I am trying to print content type as "application/pdf" in the
XML using XML::Writer module
$cContent = "applciation/pdf"; $self->_tagChar("ContentType",$cContent);
where $cContent is coming from the database and the above
code prints like this
<Content></Content>
i.e. blank
but if I write it hard code then its working fine
i.e.
$self->_tagChar("ContentType","application/pdf");
and this prints as
<Content>application/pdf</Content>
Please help me here and advise

Replies are listed 'Best First'.
Re: Issue in printing content type in XML
by davies (Monsignor) on Sep 13, 2010 at 11:02 UTC
    Just a wild guess, as I don't speak XML or HTML, but could the typo in $cContent = "applciation/pdf"; have anything to do with it?
    s/ciat/icat

    Regards,

    John Davies
      The issue is "application/pdf" is coming from database so
      this can be any value so is there anything wrong with the
      perl code?

        Most likely what you are reading "from the database" is not what you are handing to ->_tagChar(). Debug your code or post the relevant section of your code or, even better, a self-contained program that is shorter than 20 lines and still has the problem.

        As davies asked, could the problem be with

        $cContent = "applciation/pdf";
                        ///\              ?
Re: Issue in printing content type in XML
by ikegami (Patriarch) on Sep 13, 2010 at 17:57 UTC

    XML::Writer doesn't have a _tagChar method. It never has, as far as I can tell, and I went back to version 0.1 in 1999. It has dataElement for that purpose.

    That means you're probably using a home grown module with the same name, so there's no telling what it does. But the most likely problem is that you are mistaken as to what $cContent contains.

      Sorry for creating the confusion here, the _tagChar is the subroutine written by me only
      and it looks like this
      sub _tagChar { my $self = shift; my ($tag, $data) = @_; return unless(defined($tag) && defined($data)); vverbose(9,"Tag: ($tag), Data: ($data)"); $self->xml->startTag("$tag"); $self->xml->characters($data); $self->xml->endTag("$tag"); }
      and the characters sub of XML::Writer looks like this
      my $characters = sub { my $data = $_[0]; if ($data =~ /[\&\<\>]/) { $data =~ s/\&/\&amp\;/g; $data =~ s/\</\&lt\;/g; $data =~ s/\>/\&gt\;/g; } &{$escapeEncoding}($data); $output->print($data); $hasData = 1; };
      but the question here is again when I take the data in a variabled the
      value doesnt get replaced and if I pass the hardcode value it gets replaced
      i.e. application/pdf
      Please help and advise again.

        Please help and advise again.

        Nothing's changed. I'm sticking to my earlier diagnosis.