Git Product home page Git Product logo

response-xml's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

response-xml's Issues

Facebook products feed XML

Hello,

I want to create an XML response to feed products for Facebook, but I receive an error when I use g:id.
I need to create a response like this:


<g:gtin>12345678912345</g:gtin>
<g:google_product_category>Toys & Games > Toys > Executive Toys > Magnet Toys</g:google_product_category>
<g:id>SKU-123123-RED</g:id>
<g:title>WidgetThing</g:title>
<g:description>This product is the product you need to do the thing</g:description>
<g:link>link example</g:link>
<g:image_link>image link</g:image_link>

If I use 'g-description' => 'test description' is working perfect, but if I use 'g:description' => 'test description' I receive the error from the photo attached.

Can you please help me with this?

Thank you in addvance
xml

XML response with properties

how can i do a XML response like this?

<?xml version="1.0" encoding="UTF-8"?>
<gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd"
                 xmlns="http://www.isotc211.org/2005/gmd"
                 xmlns:gco="http://www.isotc211.org/2005/gco"
                 xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/gmd.xsd http://www.isotc211.org/2005/srv http://schemas.opengis.net/iso/19139/20060504/srv/srv.xsd">
  <gmd:fileIdentifier>
      <gco:CharacterString>1d630b94-fe8a-4570-9b58-0f6eb6e64fa5</gco:CharacterString>
  </gmd:fileIdentifier>
  <gmd:language>
      <gmd:LanguageCode xmlns="" codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="eng"/>
  </gmd:language>
</gmd:MD_Metadata>

How to set default response content-type?

Hello,

I'm using response()->preferredFormat() . Sometimes I like to get xml or json, depending on the Accept header.

If I don't set the Accept header, my API will return JSON (which is fine) However the content-type isn't set in that case.

How can I set the default content-type to application/json in case I didn't provide the Accept header?

I think we can set it to JSON here:

return $this->json($data, $status, array_merge($headers, ['Content-Type' => $request->headers->get('Accept')]));

Roy

Problems with collections lumen 6.x

When i try to response this collection:
$results =[[ 'first_name' => 'John', 'last_name' => 'Smith', ],[ 'first_name' => 'Jorge', 'last_name' => 'Casma', ],[ 'first_name' => 'Christian', 'last_name' => 'Cruz', ]];
i get this error:
DOMException Invalid Character Error in ArrayToXml.php line 35

at ArrayToXml->__construct(array(array('first_name' => 'John', 'last_name' => 'Smith'), array('first_name' => 'John', 'last_name' => 'Smith'), array('first_name' => 'John', 'last_name' => 'Smith')), 'Users', true, null, '1.0', array())
in ArrayToXml.php line 59

at ArrayToXml::convert(array(array('first_name' => 'John', 'last_name' => 'Smith'), array('first_name' => 'Jorge', 'last_name' => 'Casma'), array('first_name' => 'Christian', 'last_name' => 'Cruz')), 'Users')
in ResponseXmlServiceProvider.php line 72
...

Setting encoding tag in response header

Hi,

I'm using the response-xml to return TwiML xml objects to Twilio.

Twilio requires a header e.g.

Currently, the service returns

Is there a way to set the encoding?

Thanks,

Ronnie Serr

Duplicate Keys

How would I achieve this:

            $xml = [
                'DATAPACKET' =>  [
                    '_attributes' => [
                        'Version' => '2.0'
                    ],
                    'METADATA' => [
                        'FIELDS' => [
                            'FIELD' => ['_attributes' => [ 'attrname' => 'InternetID', 'fieldtype' => 'i4']],
                            'FIELD' => ['_attributes' => [ 'attrname' => 'HasMinimumData', 'fieldtype' => 'boolean']],
                            'FIELD' => ['_attributes' => [ 'attrname' => 'AppDate', 'fieldtype' => 'dateTime']],
                            'FIELD' => ['_attributes' => [ 'attrname' => 'AppTime', 'fieldtype' => 'string', 'WIDTH'=>'20']],
                            'FIELD' => ['_attributes' => [ 'attrname' => 'HouseholdSize', 'fieldtype' => 'i4']],
                            'FIELD' => ['_attributes' => [ 'attrname' => 'MemberCount', 'fieldtype' => 'i4']],
                        ]
                    ]
                ]
            ];

I would imagine only one FIELD element would exist -- if it ran at all. Or am I missing something.

preferredFormat() and Content-Type merge in browser

Hi,

while testing ->preferredFormat() with Chrome I got an ERR_INVALID_SIGNED_EXCHANGE error.

The response had a bad content-type, as it uses the full Accept-Header, e.g.

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9; charset=UTF-8

Of course, for API requests only sending an Accept-Header like application/xml or application/json the original code works.

I needed to merge the fixed xml / json content-types as done in other places in the code:

if (Str::contains($request->headers->get('Accept'), 'xml')) {
    return $this->xml($data, $status, array_merge($headers, ['Content-Type' => 'application/xml']), $xmlRoot, $encoding);
}
return $this->json($data, $status, array_merge($headers, ['Content-Type' => 'application/json']));

Thanks for considering the change in the repository.

BadMethodCallException ResponseFactory::xml does not exist.

Hey Mark, this is exactly what I'm looking for with a project I'm working on however I'm getting the error
ResponseFactory::xml does not exist.

I am using the latest Lumen 5.8, fresh with your package from composer (and nothing else) and have add the Service Provider to bootstrap/app.php.

I've updated the default route to:
$router->get('/', function () {
return response()->xml(['title' => 'one', 'name' => 'two']);
});

Which works for json response however not xml. I'm new to Laravel/Lumen so it's probably just something I'm missing. Any help would be appreciated.

PHP Fatal error: Allowed memory size

After running: composer require mtownsend/response-xml

I get the following error:

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///cygdrive/c/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///cygdrive/c/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

php version 7.2.11

Composer.json

{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
    "php": "^7.2",
    "doctrine/dbal": "^2.10",
    "guzzlehttp/guzzle": "^6.5",
    "laravel/lumen-framework": "^6.0",
    "mtownsend/response-xml": "^2.0",
    "sentry/sentry-laravel": "^1.7"
},
"require-dev": {
    "fzaninotto/faker": "^1.4",
    "phpunit/phpunit": "^8.0",
    "mockery/mockery": "^1.0"
},
"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/"
    ]
},
"scripts": {
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ]
},
"config": {
    "preferred-install": "dist",
    "sort-packages": true,
    "optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}

If you need any other information please let me know.

How to add encoding and other attributes to the generated XML tag response

I would like to learn how to add attributes to the XML tag

Currently my response results to the below code

<?xml version="1.0"?>
<Response>
    <Param>
        <Key>InvoiceNumber</Key>
        <Value>988899999</Value>
    </Param>
</Response>

I would like to get something like

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
    <Param>
        <Key>InvoiceNumber</Key>
        <Value>988899999</Value>
    </Param>
</Response>

Any help is appreciated.

How to add attribute to specific tag from generated XML

So, i use array to send response like this :

$response = [ 'status' => 200, 'message' => 'Success', 'description' => '', 'data' => $user->toArray() ];

when i use return response()->xml($response); it return this :

<?xml version="1.0"?>
<response>
    <status>200</status>
    <message>Success</message>
    <description></description>
    <data>
        <id>25</id>
        <name>Test 10</name>
        <email>[email protected]</email>
        <email_verified_at>2021-01-05 12:12:12</email_verified_at>
        <photo></photo>
        <gender>male</gender>
        <role>2</role>
        <active>1</active>
        <deleted_at></deleted_at>
        <remember_token></remember_token>
        <created_at>2021-01-07T03:20:02.000000Z</created_at>
        <updated_at>2021-01-07T03:20:02.000000Z</updated_at>
    </data>
    <data>
        <id>24</id>
        <name>Test 9</name>
        <email>[email protected]</email>
        <email_verified_at>2021-01-05 12:12:12</email_verified_at>
        <photo></photo>
        <gender>male</gender>
        <role>2</role>
        <active>1</active>
        <deleted_at></deleted_at>
        <remember_token></remember_token>
        <created_at>2021-01-07T03:07:26.000000Z</created_at>
        <updated_at>2021-01-07T03:07:26.000000Z</updated_at>
    </data>
</response>

i want to add id attribute to <data> tag like this :

<response>
    <status>200</status>
   <message>Success</message>
    <description></description>
    <data id="user-25">
       <id>25</id>
       <name>Test 10</name>
        <email>[email protected]</email>
        <email_verified_at>2021-01-05 12:12:12</email_verified_at>
        <photo></photo>
        <gender>male</gender>
        <role>2</role>
        <active>1</active>
        <deleted_at></deleted_at>
        <remember_token></remember_token>
        <created_at>2021-01-07T03:20:02.000000Z</created_at>
        <updated_at>2021-01-07T03:20:02.000000Z</updated_at>
    </data>

    <data id="user-24">
        <id>24</id>
        <name>Test 9</name>
        <email>[email protected]</email>
        <email_verified_at>2021-01-05 12:12:12</email_verified_at>
        <photo></photo>
        <gender>male</gender>
        <role>2</role>
        <active>1</active>
        <deleted_at></deleted_at>
        <remember_token></remember_token>
        <created_at>2021-01-07T03:07:26.000000Z</created_at>
        <updated_at>2021-01-07T03:07:26.000000Z</updated_at>
    </data>
</response>

Any ideas to do that?

How to make <![CDATA[letters...]>?

<xml>
  <FromUserName><![CDATA[gh_88888]]></FromUserName>
  <ToUserName><![CDATA[osuIWrbuQk]]></ToUserName>
  <CreateTime>1593256411</CreateTime>
  <MsgType><![CDATA[text]]></MsgType>
  <Content><![CDATA[模拟2]]></Content>
  <MsgId>22809948321952517</MsgId>
</xml>

DOMException: Invalid Character Error in file /vendor/spatie/array-to-xml/src/ArrayToXml.php on line 42

I am trying to return a collection as xml using the following code snippet:

$data = Order::all();
return response()->xml($data);

However, I am getting the following response:
DOMException: Invalid Character Error in file /vendor/spatie/array-to-xml/src/ArrayToXml.php on line 42

I am using the following versions:
response-xml: ^2.0
Laravel Framework: ^8.40
PHP: 8.0.5

Have I made a silly mistake somewhere?

Cannot have two stub names the same

If for example i do the following

    $data = [
    'result' => [
                    'ivr_info' => [
                        'variables' => [
                            'variable' => ['name' => 'cid_prefix','value' => $cid_prefix],
                            'variable' => ['name' => 'provider','value' => $provider],
                        ],
                    ],
                ]
    ];

The second variable stub overwrites the first one and only one is returned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.