Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

XML::Writer entity transformation issue

by mifflin (Curate)
on Jan 20, 2006 at 18:14 UTC ( [id://524546]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using XML::Writer to build an xml file to load our IBM websphere commerce database. The xml spec I have to use uses attributes for all the data, so i cannot use any cdata to preserve data. The problem I'm having is that some of the data I have already has some entities in it. For exampe: the copy right symbol is in my description in my database as ±

When I send that data through XML:Writer the ampersand gets transformed in the data to ±

Is there any way to make XML::Writer leave exiting entities alone? Here is a sample of the code that I am using to create an entry in my xml that has the problem...

$upd_xml->emptyTag('catentdesc', catentry_id => iu_product_catentry($part, $pi), language_id => $properties{language_id}{"en_$cntryid"}, name => $pi->{NEW_SHORTNAME}, shortdescription => $pi->{NEW_SHORTNAME}, longdescription => $pi->{NEW_LONGNAME}, fullimage => $pi->{NEW_DETAIL_IMAGE}, available => '0', published => ($pi->{NEW_ISRETIRED} or $pi->{NEW_ISINVISIBLE} +? '0' : '1'), keyword => $pi->{NEW_KEYWORDS});
Is there some 'feature' in XML::Writer that I am missing that can help me?

Replies are listed 'Best First'.
Re: XML::Writer entity transformation issue
by samtregar (Abbot) on Jan 20, 2006 at 20:43 UTC
    Are you sure you want to fix this behavior? Consider that if you do the system on the other end is going to have to deal with non-ASCII characters coming out of their XML parser. If your encoding is set right then everything should still work, but I wonder if you wouldn't be happier just leaving it the way it is. If, as I imagine, this text will one day end up in a web-broswer "±" may be preferable to its UTF-8 equivalent.

    All that said, if you want a better answer you might consider posting to the perl-xml mailing-list. Questions about XML encoding frequently get good answers there and the XML::Writer author has been known to post some of them.

    -sam

Re: XML::Writer entity transformation issue
by mifflin (Curate) on Jan 20, 2006 at 19:59 UTC
    Here is some code to further illustrate
    use XML::Writer; use IO::File; $fh = IO::File->new(); open($fh, '>', \$doc); $xml = XML::Writer->new(DATA_MODE => 1, DATA_INDENT => 2, OUTPUT => $f +h); $xml->startTag('root'); $xml->emptyTag('elem', attr => '®'); $xml->endTag('root'); $xml->end; print $doc;
    This prints out...
    <root> <elem attr="&amp;reg;" /> </root>
    However, what I wanted was...
    <root> <elem attr="&reg;" /> </root>
    Is this possible with XML::Writer?
Re: XML::Writer entity transformation issue
by nobull (Friar) on Jan 20, 2006 at 19:18 UTC
    Could I suggest you simply pass your data though an entity decoder?
      I'm not sure what you mean by "Entity Decoder"
      Could you elaborate?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://524546]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-16 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found