I try to create XML file. I have 2 arrays (Products and Categories). Each array is serialized with XmlList annotation and it has the same structure.
Main class:
/**
* Products
* @var Product[]|ArrayCollection
* @SerializerType("ArrayCollection<DtoSitemapProduct>")
* @XmlList(inline=true, entry="url", namespace="products")
*/
protected $products;
/**
* Categories
*
* @Required()
* @XmlList(inline=true, entry="url", namespace="categories")
* @SerializerType("ArrayCollection<DtoSitemapCategory>")
*
* @var Category[]|ArrayCollection
*/
protected $categories;
I use namespace property for define two different classes. Classes Product and Category have the same structure. The classnames are different only:
/**
* Class Product
*
* @package DtoSitemap
* @SerializerXmlNamespace(uri="products")
*/
class Product
{
/**
* @SerializerXmlElement(cdata=false, namespace="products")
* @SerializerType("string")
* @SerializerSerializedName("loc")
*
* @var string
*/
protected $loc;
/**
* @SerializerXmlElement(cdata=false, namespace="products")
* @SerializerType("string")
* @SerializerSerializedName("lastmod")
*
* @var string
*/
protected $lastmod;
SerializedName annotation does not work because at the end XML file looks like this:
<ns-50b9e781:url xmlns:ns-50b9e781="products">
<ns-50b9e781:loc>https://site.ru/</ns-50b9e781:loc>
<ns-50b9e781:lastmod>2020-10-10</ns-50b9e781:id>
</ns-50b9e781:url>
But it MUST looks like this:
<url xmlns:ns-50b9e781="products">
<loc>https://site.ru/</loc>
<lastmod>2020-10-10</id>
</url>
I don’t understand what the mistake is. Help me please.
Source: Symfony Questions
Was this helpful?
0 / 0