RE: LibXML: How do I serialize an attribute like this Attr="{" to file
by other posts by this author
Jan 20 2004 3:07AM messages near this date
view in the new Beta List Site
Character encodings driving me nuts
|
Re: LibXML: How do I serialize an attribute like this Attr="{" to file
If I want to have an output as below
<?xml version="1.0"?>
<A> <AA Attr="ƒ">xxx</AA></A>
I have to use setAttribute("Attr",chr(131)). But executing this call will get me the followi
ng error
Can't coerce UNKNOWN to string in entersub at C:/Perl/site/lib/XML/LibXML.pm line 756.
-----Original Message-----
From: Petr Pajas [mailto:pajas@[...].cz]
Sent: Monday, January 19, 2004 8:03 PM
To: Derek Chen (RD-TW)
Cc: perl-xml@[...].com
Subject: Re: LibXML: How do I serialize an attribute like this Attr="{" to file
<Derek_Chen@[...].tw> writes:
> My example is as below
>
> ------------------------------
> use XML::LibXML;
>
> my $parser = XML::LibXML->new();
> my $doc = $parser->parse_string(<<EOF);
> <A><AA Attr="B">xxx</AA></A>
> EOF
>
>
> @AA=$doc->getDocumentElement()->getElementsByTagName("AA");
> $AA[0]->setAttribute("Attr","{");
> $doc->toFile("a.xml");
> ------------------------------
> open a.xml you'll see <AA Attr="&#123;">
Ok, I didn't realize from the first mail you wrote that the attribut
is not a result of parsing xml but is rather created with
setAttribute. Your problem is thus not related to serialization but
to insertion. You cannot use character entities in setAttributes or
other DOM functions. Instead use the corresponding UTF-8 character You
may for example try setAttribute("Attr",chr(123)).
Petr
>
> -----Original Message-----
> From: Petr Pajas [mailto:pajas@[...].cz]
> Sent: Thursday, January 08, 2004 10:58 PM
> To: Derek Chen (RD-TW)
> Cc: perl-xml@[...].com
> Subject: Re: LibXML: How do I serialize an attribute like this Attr="{" to file
>
>
> <Derek_Chen@[...].tw> writes:
>
> > Hi,
>
> > I want my xml file having an element like this <abc
> > Attr="{"/>. But when I call $doc->toFile it becomes <abc
> > Attr="&#123;">. What should I do? Thanks.
> >
> > Derek
>
> Hm, I check with various setups, including the latest one using CVS
> versions of libxml2 and XML-LibXML and I cannot reproduce the problem.
> Please specify your libraries versions and send a functional
> reproducible example code demonstrating the behaviour you describe and
> XML file to test it with.
>
> -- Petr
>
> _______________________________________________
> Perl-XML mailing list
> Perl-XML@[...].com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Bart Schuller
Bjoern Hoehrmann
|