ikeikeikeike / go-sitemap-generator

go-sitemap-generator is the easiest way to generate Sitemaps in Go
https://github.com/ikeikeikeike/go-sitemap-generator
MIT License
218 stars 65 forks source link

Elements for Image are serialized out of order. #28

Open johnelliott opened 5 years ago

johnelliott commented 5 years ago

I am new to go but not sitemaps. I am not very experienced writing go so there may be something I do not understand that I am doing causing the behavior.

Context:

Generating a sitemap with URLs and Images.

Problem:

XML that elements are out of order. The XML fails to validate with xmllint: ./mymappath/sitemap/sitemap1.xml:72: element caption: Schemas validity error : Element '{http://www.google.com/schemas/sitemap-image/1.1}caption': This element is not expected. Expected is ( {http://www.google.com/schemas/sitemap-image/1.1}loc ).

Here is the offending xml:

  <image:image>
    <image:caption>hellothecaption</image:caption>
    <image:loc>https://example.com/img</image:loc>
  </image:image>

I would expect that the xml elements are in the same order for all urls, but instead sometimes they are out of order.

Different runs produce different numbers of the problem on different data. I first blamed my code and hard-coded the image data map, but I still got the same varying order. I wonder if it is the way etree is used or the way xml is used in etree.