I have model with several fields that look like this:
class XMLData(models.Model):
name = models.CharField()
description = models.CharField()
price = models.CharField()
and xml data that wrapped in string, xml data look like this:
<Root>
<Header>
<information>info</information>
</Header>
<Main>
<Product>
<Name>name1</Name>
<Description>description1</Description>
<Price>1</Price>
</Product>
<Product>
<Name>name2</Name>
<Description>description2</Description>
<Price>2</Price>
</Product>
</Main>
</Root>
My question is: should i replace children nodes Product
to the parent node and should i rename tags Name
, Description
, Price
to name
, description
, price
?
I tried to deserialize using this code:
for product in serializers.deserialize("xml", xmldata):
savedata = XMLData(product)
savedata.save()
so I hoped that will rise some errors and i would understand what to do next, but there was no errors and xml data didn't save to database.
Hope you understand my problem and thank you for your answer.