Denoteone
Denoteone

Reputation: 4055

send string as XML

I have to send a string formatted as XML to a web service as an XML document. What is the best way to turn my string

 $input_xml = "
<WEB>
<header>
<WebSiteID>WGI</WebSiteID>
<WebDocNumber>Doc10</WebDocNumber>
<OrderCaptureDateTime>10/07/2013</OrderCaptureDateTime>
</header>
<item>
<ItemNumber>FG-00087</ItemNumber>
<ReplacementItem></ReplacementItem>
<Quantity>2</Quantity>
<UnitPrice>6.31</UnitPrice>
<SalesTaxCode></SalesTaxCode>
<SalesTaxAmt>0</SalesTaxAmt>
</item>
</WEB>";

I was using $xmlget = simplexml_load_string($input_xml); and just sending $xmlget to the SOAP application.

$requestParams = array(
    'XMLDocNumber' => 'Test_Doc',
    'InboundXML' =>  $xmlget,
    'sStatus' =>''
);

The receiver of the data is say the XML is not in the "Correct Format" I am not sure which end the issue is stemming from but I thought i would ask for help.

EDIT

Based on the answers I got below I am now just sending the string of XML data. But now I am getting the following error from the SOAP application

stdClass Object ( [InboundApprovedXMLResult] => [sStatus] => Invalid XML Header Format;

I even added the XML header to my string so now it begins with this: <?xml version="1.0" encoding="UTF-8"?> still getting the same error.

Upvotes: 0

Views: 275

Answers (2)

Amal Murali
Amal Murali

Reputation: 76656

simplexml_load_string() loads the XML string and returns an object, but you should be sending the actual string instead.

Change your code to:

$requestParams = array(
    'XMLDocNumber' => 'Test_Doc',
    'InboundXML' =>  $input_xml,
    'sStatus' =>''
);

Upvotes: 1

hek2mgl
hek2mgl

Reputation: 157992

I don't know your service description (WSDL) but I guess it should be:

$requestParams = array(
    'XMLDocNumber' => 'Test_Doc',
    'InboundXML' =>  $input_xml,
    'sStatus' =>''
);

Passing a simple_xml_element makes no sense for me.

Upvotes: 1

Related Questions