Reply
Member
Posts: 5
Registered: ‎12-07-2020
Accepted Solution

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.
 
 

Accepted Solutions
Solution
Accepted by topic author 1MSC2020
‎01-04-2021 10:06 AM
Posts: 492
Topics: 0
Kudos: 99
Blog Posts: 0
Ideas: 0
Solutions: 42
Registered: ‎04-28-2017

Re: XML namespace throwing 500 Error.

[ Edited ]

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

View solution in original post


All Replies
Solution
Accepted by topic author 1MSC2020
‎01-04-2021 10:06 AM
Posts: 492
Topics: 0
Kudos: 99
Blog Posts: 0
Ideas: 0
Solutions: 42
Registered: ‎04-28-2017

Re: XML namespace throwing 500 Error.

[ Edited ]

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
Member
Posts: 1
Registered: ‎01-11-2021

Re: XML namespace throwing 500 Error.

I had the same problem on my website https://hoekstra-slotenmaker.nl/ by means of this code it is solved for me in any case:


$ transRequestXmlStr = <<< XML
<? xml version = "1.0" encoding = "UTF-8"?>
<createTransactionRequest xmlns = "http: //AnetApi/xml/v1/enschema/AnetApiSchema.xsd">

 

I do use a provider that automatically adjusts the XML code for the wordpress websites

Member
Posts: 1
Registered: ‎06-30-2021

Re: XML namespace throwing 500 Error.

Same for me this code did solved for me :

$ transRequestXmlStr = <<< XML
<? xml version = "1.0" encoding = "UTF-8"?>
<createTransactionRequest xmlns = "http: //AnetApi/xml/v1/enschema/AnetApiSchema.xsd">

https://slotenmaker-bouwmans.be/