Viewed   228 times

I want to output raw xml in a manner similar to but using PHP.

I have a very simple php script on my webserver:


      $output = "<root><name>sample_name</name></root>";
      print ($output);

All I can see in Chrome/firefox is "sample_name". I want to see:


I cannot find a tutorial for anything THIS simple.




By default PHP sets the Content-Type to text/html, so the browsers are displaying your XML document as an HTML page.

For the browser to treat the document as XML you have to set the content-type:

header('Content-Type: text/xml');

Do this before printing anything in your script.

Friday, September 23, 2022

On some installations, there is a bug in pecl. Find this line;

exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@" 

remove the -n

If you want to script it, try:

sed -i "$ s|-n||g" /usr/bin/pecl
Monday, October 24, 2022

Lots of custom parsing. Sorry. There is no simple solution.

There is no standard format for WHOIS responses. At a minimum, most registries have a slightly different format for responses; additionally, "thin registries" such as .COM and .NET require every registrar to implement their own WHOIS server, each of which has its own slightly different, idiosyncratic format.

As others have noted, there are paid APIs available to do this parsing for you. Depending on your needs, this may be a more appropriate solution than trying to parse several thousand different formats yourself.

Sunday, December 11, 2022

The call should look like this:, xml: "<elem />")

Or if you just want to set one or multiple namespaces then create a client as follows (without WSDL):

client = Savon.client(
  :endpoint => '',
  :namespace => '',
  :namespaces => { 'ns1' => '',
                   'ns2' => '' },
  :log => true,
  :log_level => :debug,
  :pretty_print_xml => true

The namespaces are a Hash parameter.

Tuesday, November 29, 2022

If anyone should be interested, i have provided the correct answer:

$soapUrl = "";

$xml_post_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12=""><soap12:Body><SearchCollectionPoint xmlns=""><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvŠgen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';

$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch); 

$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);

$parser = simplexml_load_string($response2);
Thursday, September 29, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :