0

I have the list of images that I wrote in xml and I can be able to run them on xbmc.

Here is the list of the images in the xml:

<?xml version="1.0" encoding="utf-8"?>
<window type="dialog">
    <allowoverlay>no</allowoverlay>
    <coordinates>
        <system>1</system>
        <posx>0</posx>
        <posy>0</posy>
    </coordinates>

<controls>
    <control type="image" id="1">
       <description>Image1</description>
       <posx>307</posx>
       <posy>7</posy>
       <width>164</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image1_blue.jpg</texturefocus>
       <texturenofocus>image1_yellow.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="2">
       <description>Image2</description>
       <posx>471</posx>
       <posy>7</posy>
       <width>201</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image2_yellow.jpg</texturefocus>
       <texturenofocus>image2_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="4">
       <description>Image3</description>
       <posx>671</posx>
       <posy>7</posy>
       <width>177</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image3_yellow.jpg</texturefocus>
       <texturenofocus>image3_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>

    <control type="image" id="6">
       <description>image4</description>
       <posx>848</posx>
       <posy>7</posy>
       <width>176</width>
       <height>102</height>
       <visible>true</visible>
       <texturefocus>image4_yellow.jpg</texturefocus>
       <texturenofocus>image4_blue.jpg</texturenofocus>
       <onup>2</onup>
       <ondown>3</ondown>
       <onleft>1</onleft>
       <onright>1</onright>
    </control>
</controls>
</window>

I want to know how do you write on if statement in python for xbmc that if the image include the id is exist then I want to know how I can change the image using the id?

  • Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). –  Jan 09 '14 at 03:03
  • You need an XML parser to get the strings (filepaths), then you can check if the files exist using the examples [here](http://stackoverflow.com/questions/82831/how-do-i-check-if-a-file-exists-using-python). – Keeler Jan 09 '14 at 17:20
  • @Keeler yes that is what I'm trying to do to get the strings through an XML parser. I'm sorry but I had a look the link you sent which there are alot of parser to get the strings and I don't know which one I should use for XML parser. Could you please post an example XML parser that I should use? –  Jan 09 '14 at 17:29
  • @Keeler can you please tell me which XML parser that I should use in that link you have already sent? –  Jan 09 '14 at 17:57

1 Answers1

0

Python comes with the xml module which has the useful ElementTree that will do what you need.

Here's an example of how to use it:

import xml.etree.ElementTree as ET

filename = 'name_of_the_xml_file.xml'
tree = ET.parse(filename)
root = tree.getroot()
controls = root.find('controls')

for control in controls.findall('control'):
    # Here are the image filenames, focus and nofocus.
    focus = control.find('texturefocus').text
    nofocus = control.find('texturenofocus').text
    print('texturefocus={0}, texturenofocus={1}'.format(focus, nofocus))

Further reading: xml.etree.ElementTree documentation.

Keeler
  • 2,102
  • 14
  • 20
  • @Keeler Thanks for this. I have four images that run in the xbmc. I want to create for the if statement that if the image is exist which return to true then to do something? for e.g. `if os.path.exists('Q:\\resources\skins\Default\media\tvguide_yellow.png') == True:` I tried to use it but it did not work. Any idea? –  Jan 09 '14 at 18:43