Hi Issuer,

Plz select options :
1. Follow someone else convert xml to dict, and then process forward.
2. See this document python DOM XML doc, especial in 20.6.2.3 section
https://docs.python.org/3.6/library/xml.dom.html#domimplementation-objects

see nodelist.item(i) and __getitem__() method.

On Wed, Nov 6, 2019, 18:13 Nuno Vieira <nuno.vieira.tecnoin...@gmail.com>
wrote:

> Thanks for your feedback.
>
> The problem is if i set all the urls to None before, and a property have
> only 6 images of 20, on database saves the 6 images of this property and
> saves also the other image columns with images from a different property,
> but when i use the else blocks instead of setting all to None before the
> loop, it only saves the first (nr 1) and the last image (nr 6) of the
> property.
> I have no idea why this behavior.
>
> I really need some help.
> Thanks.
>
> sexta-feira, 25 de Outubro de 2019 às 01:01:45 UTC+1, Arthur Antoine
> escreveu:
>>
>> The image urls are being set to None on every iteration where the id
>> doesn't match. Try setting all of the urls to None before the loop, then
>> remove the else blocks.
>>
>> On Thursday, October 24, 2019 at 11:28:00 AM UTC-4, Nuno Vieira wrote:
>>>
>>> Hi,
>>>
>>> i receive an xml file and i am parsing the values and sving them to
>>> database.
>>>
>>>> XML Example:
>>>
>>> <property>...</property>
>>> <property>...</property>
>>> <property>...</property>
>>> <property>
>>> <id>9896</id>
>>> <date>2019-07-11 13:12:09</date>
>>> <ref>BC30401</ref>
>>> <price>895000</price>
>>> <currency>EUR</currency>
>>> <price_freq>sale</price_freq>
>>> <part_ownership>0</part_ownership>
>>> <leasehold>0</leasehold>
>>> <new_build>0</new_build>
>>> <surface_area>
>>> <built>915</built>
>>> </surface_area>
>>> <type>Villa</type>
>>> <location>
>>> <latitude>37.134720</latitude>
>>> <longitude>-8.020436</longitude>
>>> </location>
>>> <location_detail>optional location detail</location_detail>
>>> <town>Vilamoura</town>
>>> <province>Algarve</province>
>>> <country>Portugal</country>
>>> <beds>4</beds>
>>> <baths>3</baths>
>>> <pool>1</pool>
>>> <images>
>>> <image id="1">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7064.jpg
>>> </url>
>>> </image>
>>> <image id="2">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7065.jpg
>>> </url>
>>> </image>
>>> <image id="3">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7066.jpg
>>> </url>
>>> </image>
>>> <image id="4">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7067.jpg
>>> </url>
>>> </image>
>>> <image id="5">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7068.jpg
>>> </url>
>>> </image>
>>> <image id="6">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7069.jpg
>>> </url>
>>> </image>
>>> <image id="7">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7071.jpg
>>> </url>
>>> </image>
>>> <image id="8">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7072.jpg
>>> </url>
>>> </image>
>>> <image id="9">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7073.jpg
>>> </url>
>>> </image>
>>> <image id="10">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7075.jpg
>>> </url>
>>> </image>
>>> <image id="11">
>>> <url>
>>> https://bc-villas.com/wp-content/uploads/2019/07/IMG_7077.jpg
>>> </url>
>>>
>>>> </image>
>>>
>>>
>>> It´s all working ok but with images its a litle confused because i can
>>> only save the first and the last image. If a property have 12 pictures i
>>> can only save the picture nr 1 and picture nr 12, if the property have 8
>>> pictures i can only save picture nr1 and picture nr 8. It´s weird!
>>>
>>> My code to get the pictures url:
>>> img             = props.find('images')
>>>
>>>                         for child in img:
>>>
>>>                                 if child.get('id') == '1':
>>>                                        img_main_url = child.find('url'
>>> ).text
>>>
>>>                                if child.get('id') == '2':
>>>
>>>                                        img_1_url = child.find('url'
>>> ).text
>>>                                else:
>>>                                        img_1_url = None
>>>                                if child.get('id') == '3':
>>>                                        img_2_url = child.find('url'
>>> ).text
>>>                                else:
>>>                                        img_2_url = None
>>>                                if child.get('id') == '4':
>>>                                        img_3_url = child.find('url'
>>> ).text
>>>                                else:
>>>                                        img_3_url = None
>>>                                if child.get('id') == '5':
>>>                                        img_4_url = child.find('url'
>>> ).text
>>>                                else:
>>>                                        img_4_url = None
>>>
>>>
>>> I could use a litle help from someone more experienced in django.
>>>
>>> Thanks for your help
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/249cb5ad-668e-4fe9-aa54-f55c9e3a8ae6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/249cb5ad-668e-4fe9-aa54-f55c9e3a8ae6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP5HUWoux2wi4%3DkZxySKQHtkb5YbqOARZJEvqeXMO%2BVT91t5BA%40mail.gmail.com.

Reply via email to