cancel
Showing results for 
Search instead for 
Did you mean: 

XML namespace throwing 500 Error.

I am using the transactionCaller.php script in Laravel. It is giving me an error "

local.ERROR: simplexml_load_string(): namespace warning : xmlns: URI AnetApi/xml/v1/schema/AnetApiSchema.xsd is not absolute" 
 
I was getting the same error on the creation of the XML. If found an answer that to make the namespace absolute I had to add HTTP:// before it. That worked.
 
$transRequestXmlStr=<<<XML
        <?xml version="1.0" encoding="UTF-8"?>
        <createTransactionRequest xmlns="http://AnetApi/xml/v1/schema/AnetApiSchema.xsd">
However, when I receive the XML back it has the namespace without the HTTP:// so I get the error. It is not a warning in Laravel it is a 500 error.
 
 
1MSC2020
Member
1 REPLY 1

Hello,

 

Authorize.Net uses a relative namespace path which the SDK's XML library complains about.

 

The solution is don't include the xmlns attribute in your construction of the SimpleXML element object and use SimpleXMLElement::addAttribute after the fact to add it.

 

Instead of this:

$element = new SimpleXMLElement('<createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"/>');

 

Do this:

$element = new SimpleXMLElement('<createTransactionRequest/>');

$element->addAttribute('xmlns', 'AnetApi/xml/v1/schema/AnetApiSchema.xsd');

To avoid these errors when parsing the response, simply strip the xmlns attribute out of the response before parsing it with SimpleXML using the following:

 

$result = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $result);

($result in this example is the raw XML as returned by Authorize.Net.)

Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor