Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get XML attribute from content #202

Open
denis909 opened this issue Feb 21, 2020 · 3 comments
Open

Can't get XML attribute from content #202

denis909 opened this issue Feb 21, 2020 · 3 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@denis909
Copy link

I have this result from server:

<?xml version="1.0" encoding="UTF-8"?>
<yandexsearch version="1.0"><response date="20200221T142812"><error code="15">Для заданного поискового запроса отсутствуют результаты поиска.</error></response></yandexsearch>

$response->data return this array:

array(2) {
  ["@attributes"]=>
  array(1) {
    ["version"]=>
    string(3) "1.0"
  }
  ["response"]=>
  array(2) {
    ["@attributes"]=>
    array(1) {
      ["date"]=>
      string(15) "20200221T150244"
    }
    ["error"]=>
    string(119) "Для заданного поискового запроса отсутствуют результаты поиска."
  }
}

code="15" is not in data array. I can get this code manually, but I think it would be better if it is in @attributes in data.

$xml = simplexml_load_string($response->content, 'SimpleXMLElement', LIBXML_NOCDATA);
$code = (string) $xml->response->error->attributes()->code;
@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Feb 21, 2020
@samdark
Copy link
Member

samdark commented Feb 21, 2020

Could you provide some code that could be used to reproduce it?

@denis909
Copy link
Author

denis909 commented Feb 21, 2020

$client = new \yii\httpclient\Client;

$response = new \yii\httpclient\Response(['client' => $client]);

$response->setContent('<?xml version="1.0" encoding="UTF-8"?>
<yandexsearch version="1.0"><response date="20200221T142812"><error code="15">Для заданного поискового запроса отсутствуют результаты поиска.</error></response></yandexsearch>');

var_dump($response->data);

@denis909
Copy link
Author

php 7.3.2 Windows

@samdark samdark added this to the 2.0.13 milestone Feb 21, 2020
@samdark samdark added the type:bug Bug label Feb 22, 2020
@samdark samdark modified the milestones: 2.0.13, 2.0.14 Dec 23, 2020
@samdark samdark removed this from the 2.0.14 milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

2 participants