Re: Keeping numeric entities intact when parsing and serializing?

Petr Pajas <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
2009/10/9 Nicolas Mendoza <[email protected]>:
> På Fri, 09 Oct 2009 17:54:39 +0200, skrev Nicolas Mendoza
> <[email protected]>:
>
>> Is there some way to keep the entities intact when parsing and
>> serlalizing
>> numeric entities?

Nicolas,

no, libxml2's APIs do not provide any such thing. The information
about which characters were encoded using entities and which not  is
not made available by the XML parser.

Basically you can expect the following behavior from libxml2's (and
hence XML::LibXML's) serializer:

- if no encoding is specified for the document in the <?xml ...?>
declaration, any non-ascii character is encoded using an entity

- if an ecoding *is* specified for the document, then characters valid
for that encoding are serialized literally, whereas all "foreign"
characters (not representable in the given encoding) are serialized
using entities.

-- Petr

>> $ perl -wle 'use XML::LibXML; my $xml_parser = XML::LibXML->new(); my $d
>> =
>> $xml_parser->parse_string("<xml>Resolved: &#x69; Not resolved:
>> %amp;</xml>"); print $d->toString(); '
>> <?xml version="1.0"?>
>> <xml>Resolved: i Not resolved: %amp;</xml>
>>
>
> Sorry meant this:
>
> $ perl -wle 'use XML::LibXML; my $xml_parser = XML::LibXML->new(); my $d =
> $xml_parser->parse_string("<xml>Resolved: &#39; Not resolved:
> &amp;</xml>"); print $d->toString(); '
> <?xml version="1.0"?>
> <xml>Resolved: ' Not resolved: &amp;</xml>
>
> But same problem remains. Also I can't re-escape later I'm afraid.
>
> --
> Sendt med Operas revolusjonerende e-postprogram: http://www.opera.com/mail/
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.