Skip to content

Can't get XML attribute from content  #202

@denis909

Description

@denis909

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions