Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: XML::Parser does not parse the Symbol

by mirod (Canon)
on Jul 11, 2013 at 10:57 UTC ( #1043693=note: print w/ replies, xml ) Need Help??


in reply to XML::Parser does not parse the Symbol

What's the error message? Without it I can only guess...

... that maybe the inverted question mark is encoded in extended-ascii (ISO-8859-1). Since you don't specify an encoding in the XML string, it is assumed to be in UTF-8, and you should get an "invalid character" or such error.

If in your real code the string is hard-coded in the program file, then you need to use utf8;.

If you get the data from a file, you need to either add an XML declaration specifying the encoding, pre-process the data to convert it to utf-8 or use the ProtocolEncoding option when you create the XML::Parser object (I would advise against this last solution though, better to keep the info about the encoding of the data with the data than in the code).


Comment on Re: XML::Parser does not parse the Symbol
Select or Download Code
Re^2: XML::Parser does not parse the Symbol
by gopalr (Priest) on Jul 11, 2013 at 12:17 UTC

    It is working fine if I use ProtocolEncoding

    $parser = new XML::Parser(Style => 'Tree'); $xml = $parser->parse($xml, ProtocolEncoding => 'ISO-8859-1')

    I have one more clarification, If we use ISO-8859-1, will it support to UTF-8 as well ?

      no

      Did you really read the part where I advised you NOT to use ProtocolEncoding?

      If you have to deal with XML, please educate yourself about encodings, it will pay off in the very short term.

        Please correct me if I am wrong.

        You mean that adding the encoding in the xml declaration as follows in xml file:

        <?xml version="1.0" encoding="ISO-8859-1"?>

        Is that you are suggestion?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-12-28 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls