dragonfly9527 2018-08-17 11:16 采纳率: 100%
浏览 36

使用JMS Serializer在symfony 4中反序列化xml

I am trying to de-serialize the follow XML using JMS Serializer

<?xml version="1.0" encoding="utf-8"?>
 <people>
   <person>
     <personid>1</personid>
     <personname>Name 1</personname>
   </person>
   <person>
     <personid>2</personid>
      <personname>Name 2</personname>
     </person>
</people>

My doubt is: Do i need to create a People Entity or just a Person entity is fine?

UPDATE

I have a Person entity and I am trying to get de de-serialized data like this:

$xml = "xml_as_a_string";
$serializer = SerializerBuilder::create()->build();
$xmlContent = $serializer->deserialize($xml,   
    'ArrayCollection<'.Person::class.'>', 
    'xml');

but the $xmlContent keeps coming as a empty array.

  • 写回答

0条回答 默认 最新

    报告相同问题?