php Serializer XML remove tag

I try to create XML file. I use Serializer in annotations.
Products variable:

/**
 * @var Product[]|ArrayCollection
 * @SerializerType("ArrayCollection<FeedProduct>")
 * @SerializerXmlList(inline=false, entry="url")
 */
protected $products;

Products class:

/**
 * Class Product
 *
 * @package Feed
 *
 * @SerializerXmlRoot("urlset")
 */

class Product
{
    /**
     * @SerializerXmlElement(cdata=false)
     * @SerializerType("string")
     * @SerializerSerializedName("loc")
     *
     * @var string
     */
    protected $loc;

    /**
     * @SerializerXmlElement(cdata=false)
     * @SerializerType("string")
     * @SerializerSerializedName("lastmod")
     *
     * @var string
     */
    protected $lastmod;

So I get XML file finnaly like this:

<urlset>
   <products>
      <url>
         <loc>https://site.site/1.html</loc>
         <lastmod>2020-11-07</lastmod>
      </url>          
      <url>
         <loc>https://site.site/2.html</loc>
         <lastmod>2020-11-07</lastmod>
      </url>
      <url>
         <loc>https://site.site/3.html</loc>
         <lastmod>2020-11-07</lastmod>
      </url>
...
   </products>
</urlset>

Question about <products> tag. I did not create this, I don’t want to create <products> tag. How can I remove this tag from XML file?
@SerializerXmlRoot gets only string params, I try give null param but it does not work.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *