[XML-SIG] escaping ' or " in attributes

Hefferon9 at aol.com Hefferon9 at aol.com
Sun Nov 14 00:24:14 CET 2004


Hello,
 
Please, may I ask two similar questions?  No doubt they are  silly; but I've 
looked for the answer in books, in the docs, in clp, and here,  and had no 
luck.  
 
1) What is the canonical way to escape the quotes inside of an  attribute?  I 
have a cgi script, and may be getting things from users  that I want to stuff 
inside of the attributes.  That is, I have code  like this: 
  favoriteFood=fs.getfirst('favoriteFood')  # fs is a  cgi.FieldStorage 
structure
  attrDct={'favoriteFood':favoriteFood}
and I'm afraid I'll get "Mama's" for an answer, giving me XML  like
  <choice favoriteFood='Mama's' />
(likewise, "Ben & Jerry's" gives me worries)  I've cast about  for what I 
thought were likely names, but didn't find any  .  
 
2) Similarly, in XHTML, in an href, is there some obvious function that I  
somehow overlooked to quote the ampersands? 
 
Possibly both have the same answer?
 
I can do a substitution by hand of course, but I'm trying to learn the best  
practices, and also I conceive that one of the points of a library to  give me 
peace of mind that its taken care of obscure cases that I might not  
understand.
 
Thanks in advance,
Jim Hefferon 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/xml-sig/attachments/20041113/f14d1d66/attachment.htm


More information about the XML-SIG mailing list