Search by

tarkhov / guzzle-xml

tarkhov

This package is abandoned and no longer maintained. The author suggests using the tarkhov/guzzle-xml package instead.

Guzzle XML request and response.

This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.

Package info

github.com/tarkhov/guzzle-xml

pkg:composer/tarkhov/guzzle-xml

Statistics

Installs: 41 097

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 3

v2.0.0 2026-02-02 15:19 UTC
Deleted by maintainer on 2026-10-20 08:27:23 UTC

This package is auto-updated.

Last update: 2026-10-20 08:28:19 UTC


README

Guzzle XML request and response.

Contents

  1. Compatibility
  2. Installation
    1. Composer
  3. Usage
    1. Request options
    2. Response
  4. Author
  5. License

Compatibility

Library Version
PHP >= 8.2
Guzzle >= 7.0
Symfony Serializer >= 7.0
Laravel >= 12.0

Installation

Composer

composer require tarkhov/guzzle-xml

Usage

Request options

Following example creates POST request with XML body. Option xml accepts an array that is converted to XML document. About array format and how converting works you can read in detail Symfony XmlEncoder.

<?php
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
use GuzzleXml\XmlMiddleware;

$stack = HandlerStack::create();
$stack->push(XmlMiddleware::xml(), 'xml');
$client = new Client(['handler' => $stack]);
$response = $client->post('https://example.com', [
  'xml' => [
    'package' => [
        '@language' => 'PHP',
        'name'      => 'Guzzle XML',
        'author'    => [
          '@role' => 'developer',
          '#'     => 'Tarkhov',
        ],
        'support'   => [
            'issues' => 'https://github.com/tarkhov/guzzle-xml/issues',
            'source' => 'https://github.com/tarkhov/guzzle-xml',
        ],
    ],
  ],
]);

As a result, an xml request will be sent with the header Content-type: text/xml and data with the following content:

<?xml version="1.0"?>
<package language="PHP">
   <name>Guzzle XML</name>
   <author role="developer">Tarkhov</author>
   <support>
      <issues>https://github.com/tarkhov/guzzle-xml/issues</issues>
      <source>https://github.com/tarkhov/guzzle-xml</source>
   </support>
</package>

Response

Automatically convert your JSON response to XML using middleware.

<?php
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
use GuzzleXml\XmlMiddleware;

$stack = HandlerStack::create();
$stack->push(XmlMiddleware::jsonToXml());
$client = new Client(['handler' => $stack]);
$response = $client->post('https://example.com');
$xml = $response->getBody();
echo $xml;

If your json response is:

{
   "package": {
      "@language":"PHP",
      "name":"Guzzle XML",
      "author": {
         "@role":"developer",
         "#":"Tarkhov"
      },
      "support": {
         "issues":"https:\/\/github.com\/tarkhov\/guzzle-xml\/issues",
         "source":"https:\/\/github.com\/tarkhov\/guzzle-xml"
      }
   }
}

This will automatically convert to XML like this:

<?xml version="1.0"?>
<package language="PHP">
   <name>Guzzle XML</name>
   <author role="developer">Tarkhov</author>
   <support>
      <issues>https://github.com/tarkhov/guzzle-xml/issues</issues>
      <source>https://github.com/tarkhov/guzzle-xml</source>
   </support>
</package>

Author

License

This project is licensed under the MIT License - see the LICENSE file for details.