php - Sabre XML Writer - Group repeating Elements -


i have little question sabre xml.

i prefer not develop custom writers hardcoded every php class want serialize, use mapvalueobject tell sabrexml do. unfortunatelly repeating elements not grouped.

i have php model (simplified):

class productitem contains object of class "product" , array, containing multiple productsdescriptions multilanguage.

class productitem extends model {   /**    * @var product    */   var $product;   /**    * @var productsdescription[]    */   var $descriptions; } 

class model contains information how serialize extending classes.

abstract model {   public function serialize() {     $service = new \sabre\xml\service();     $service->mapvalueobject('{}productitem', productitem::class);     $service->mapvalueobject('{}product', product::class);     $service->mapvalueobject('{}productsdescription', productsdescription::class);     $xml = $service->writevalueobject($this);     return $xml;   } } 

the xml returned looks this:

<?xml version="1.0"?> <productitem>   <product>     <id>1234</id>     <stock>100</stock>   </product>   <descriptions>     <language_code>deu</language_code>     <products_name>testdeu</products_name>   </descriptions>   <descriptions>     <language_code>eng</language_code>     <products_name>testeng</products_name>   </descriptions> </productitem> 

but want this:

<?xml version="1.0"?> <productitem>   <product>     <id>1234</id>     <stock>100</stock>   </product>   <descriptions>     <productsdescription>       <language_code>deu</language_code>       <products_name>testdeu</products_name>     </productsdescription>     <productsdescription>       <products<language_code>eng</language_code>       <products_name>testeng</products_name>     </productsdesription>   </descriptions> </productitem> 

is there way how tell sabrexml group repeating elements of class using mapvalueobjects, or have write custom serializer class productitem, collect children, sets them in array , serializes them using

sabre\xml\serializer\repeatingelements($writer, $collection, 'childname'); 

function?


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -