Tuesday, 15 July 2014

php - JMS Serializer to read xml:lang attribute -



php - JMS Serializer to read xml:lang attribute -

this related xml:lang parse in php.

we utilize jms serializer create xml requests , parse xml responses sirena-travel (airticket provider). whole scheme of annotated dtos built around serializer, , we're unlikely alter this.

there reponse xml we'd deserialize (the same in above question):

<?xml version="1.0" encoding="utf-8"?> <answer> <describe data="aircompany"> <data> <code xml:lang="ru">fw</code> <code xml:lang="en">fw</code> </data> <data> <code xml:lang="ru">ut</code> <code xml:lang="en">ЮТ</code> </data> </describe> </answer>

the question is: how specify property corresponding xml:lang attribute?

this how classes describing innermost elements like:

class describedata { /** * codes in various languages. * * @type("array<describelangelement>") * @xmllist(inline = true, entry = "code") */ private $codes = []; public function getcode($lang) { foreach ($this->codes $code) { if ($code->getlang() === $lang) { homecoming $code; } } homecoming null; } } class describelangelement { /** * element's language code. * * either "en" or "ru". * * @type("string") * @xmlattribute */ private $lang; /** * @type("string") * @xmlvalue */ private $value; }

obviously, serializer not recognize xml:lang attribute $lang property. tried couple of approaches:

add @serializedname("xml:lang") $lang property.

add namespace annotation:

@xmlnamespace(uri = "http://example.com/", prefix = "xml")

either parent node or root node, while modifying @xmlattribute annotation on $lang property like

@xmlattribute(namespace = "http://example.com/")

needless say, no success either or both of them.

i have in mind alternate solutions like:

preprocess xml convert xml:lang attribute lang. write custom deserialization handler deal describelangelement class.

but seem overkill me.

is there straight-forward way specify property xml:lang attribute jms serializer annotations?

namespace constraint: reserved prefixes , namespace names

the prefix xml definition bound namespace name http://www.w3.org/xml/1998/namespace. may, need not, declared, , must not undeclared or bound other namespace name. other prefixes must not bound namespace name, , must not declared default namespace.

from: http://www.w3.org/tr/xml-names11/#xmlreserved

therefore namespace not http://example.com/ http://www.w3.org/xml/1998/namespace.

php xml jms-serializer

No comments:

Post a Comment