Integration and Testing

Authorize.Net API questions and help with your payment integration.

Reply
Member
Posts: 1
Registered: ‎07-15-2011

using CDATA tags in name fields

Hi,

 

Newbie here... been integrating CIM api's for about 2 months... anyway, ran into an issue in using the

"createCustomerProfileRequest"  CIM api when there was an ampersand     &    included in the company name 

 

<?xml version="1.0" encoding="utf-8"?>                                          
<createCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">  
<merchantAuthentication>                                                      
<name>xxxxxxxxxxx</name>                                                       
<transactionKey>xxxxxxxxxxxxxxx</transactionKey>                           
</merchantAuthentication>                                                     
<refId>xxxxxxxxxxxxxxxxxxxxxx</refId>                                             
<profile>                                                                     
<merchantCustomerId>121121</merchantCustomerId>                            
<description>SO121121</description>                                         
<paymentProfiles>                                                             
<billTo>                                                                  
<company>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx & zzz</company>                            
<address>755</address>                                                  
<zip>10466</zip>                                                        
</billTo>

 (note that the break shown above AFTER the & does not exist in the real XML)

 

The error returned is "E00003  An error occurred while parsing Entity Name. Line 13, position 39.  ".

If i count out the line and position, that points to the ampersnad in the <company> tag.

 

My thought was that I could use the "CDATA" tag like I see in some of the API examples in the manual, usually shown in the <extraOptions>.

 

When I did that

 

   <company><![CDATA[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx & zzz]]></company>  

 

The error returned is "E00003 Invalid character in the given encoding. Line 13, position 20. "  which points to the

which points to the [  just prior to the CDATA .

 

Can we use CDATA      to wrapper special characters in the actual data values?

 

The API works fine if the ampersand is not embedded in the data.   I don't want to strip it out, because we have

customers give us the name off of the card and it does have an ampersand as part of the name that is on the card.

 

Any help, including pointing me to the documentation that explains this, would be appreciated.

 

Thanks in advance

 

Regular Contributor
Posts: 72
Registered: ‎07-06-2011

Re: using CDATA tags in name fields

[ Edited ]

Ampersand is a reserved character in XML.

 

To use it you have to first clean the input to escape it by using &amp;

 

(I always found it funny that to escape an ampersand you have to use an ampersand)

 

WHeis

 

Member
Posts: 3
Registered: ‎01-14-2014

Re: using CDATA tags in name fields

This is a bug in the AuthorizeNet SDK library (at least in 1.4.6). The library is not properly escaping XML attribute values or element text values when serializing XML documents to Strings.

Posts: 2,765
Topics: 57
Kudos: 272
Blog Posts: 67
Registered: ‎12-05-2011

Re: using CDATA tags in name fields

This issue is still open but reported in GitHub.  https://github.com/AuthorizeNet/sdk-java/issues/4

 

Richard