ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: LibXML: How do I serialize an attribute like this Attr="{" to file
by Petr Pajas other posts by this author
Jan 19 2004 12:02PM messages near this date
view in the new Beta List Site
RE: LibXML: How do I serialize an attribute like this Attr="{" to file | Re: Yet another parser
<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","&#123;");
>  $doc->toFile("a.xml");
>  ------------------------------
>  open a.xml you'll see <AA Attr="&amp;#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="&#123;" to file
> 
> 
>  <Derek_Chen@[...].tw> writes:
> 
> > Hi,
> 
> > I want my xml file having an element like this <abc
> > Attr="&#123;"/>. But when I call $doc->toFile it becomes <abc
> > Attr="&amp;#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:

Petr Pajas

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved