Hey guys,

I really appreciate your help so far! :) This one is a tough beast... I don't even know how to approach it.

Let me give you a summary version and a detailed version.

Summary version:
There are all sorts of these XML files scattered within a bunch of different folders under one directory. One file called Screens.xml tells which XML file to start with. Then, each corresponding XML files have a bunch of elements and pieces which dynamically lead to other XML files, which lead to other XML files in different ways. I need a way to create some sort of user-friendly text file with a tree navigation that shows the pathway of all of these XML files. Something like this perhaps:

Screens.xml
-->StartScreen
---->>North America
------->>>Chicago
---------->>>>MyHouse
------------->>>>>LivingRoom
------------->>>>>Kitchen
------------->>>>>Bedroom
---------->>>>MyFriend'sHouse
------------->>>>>Bathroom
------->>>Las Vegas
---------->>>>Casino
---->>South America
---->>Europe

I want this to be readable to humans, so any other suggestions would be great, because I don't find my approach to be the best.

Now for the details.
Each XML file has two tags that I want to be able to record in my text file. Either:
<AddScreen>
or
<OnClick>

For example, my StartScreen.xml may look like this:

<MyScreens>

<MyScreen Name="StartScreen" refresh="20000">

<img src="/img/map-world.jpg" X="15" Y="50" Width="800" Height="380" />

<AddScreen Screen="navIcon_fn"  X="265" Y="270" 
Params="$(%)Label$(%)::South America;;$(%)ScreenName$(%)::SouthAmericaHome;;$(%)Area$(%)::South America;;$(%)XChange$(%)::-50;;$(%)YChange$(%)::-300;;$(%)XCoord$(%)::140;;$(%)YCoord$(%)::120" />

	  <AddScreen Screen="navIcon_fn"  X="180" Y="160" 
Params="$(%)Label$(%)::North America;;$(%)ScreenName$(%)::NorthAmericaHome;;$(%)Area$(%)::North America;;$(%)XChange$(%)::-40;;$(%)YChange$(%)::-130" />


	  <AddScreen Screen="navIcon_fn"  X="420" Y="150" 
Params="%Label%::Europe;;$(%)ScreenName$(%)::EuropeHome;;$(%)Area$(%)::Europe;;$(%)XChange$(%)::-40;;$(%)YChange$(%)::-200;;$(%)XCoord$(%)::70;;$(%)YCoord$(%)::130" />

</MyScreen>


</MyScreens>

So in my text file, I would want to store the items corresponding to the %Label% or $(%)Label$(%) parameters (ex. North America or Europe) for the first level like this:

-->StartScreen
---->>South America
---->>North America
---->>Europe

But then I'd need to store the items corresponding to the %ScreenName% or $(%)ScreenName$(%) parameters (ex. SouthAmericaHome or NorthAmericaHome) in some sort of ordered array because those are the next file names like SouthAmericaHome.xml and NorthAmericaHome.xml. Then those files would have to be opened in order, screened for <AddScreen> and <OnClick> and inserted into the right spot.

Let's say there was just one <AddScreen> in SouthAmericaHome.xml and we went through it. We'd now have to go through the NorthAmericaHome.xml, which let's say looks like this:

<MyScreens>

<MyScreen Name="NorthAmericaHome" refresh="20000">

<img src="/img/NorthAmerica.png" X="10" Y="50" Width="800" Height="380" />


 <Label X="252" Y="295" bold="1" font="arial" width="170" size="16" fgcolor="0xFFFFFF">Chicago</Label>
<img src="/img/blue_ball.png" X="260" Y="275" Width="20" Height="20">
		<OnClick GoToScreen="ChicagoScreen" />    
	</img>

<Label X="610" Y="175" bold="1" font="arial" width="150" fgcolor="0xFFFFFF">Las Vegas</Label>
<img src="/img/blue_ball.png" X="630" Y="155" Width="20" Height="20">
		<OnClick GoToScreen="VegasScreen" />    
	</img>

</MyScreen>

</MyScreens>

It would be amazing if I could make the script pick up the closest Label to the OnClick, but I know that may be difficult, so let's just pick up the GoToScreen param of the <OnClick>. At this point, I'd want the text file to look something like this:

-->StartScreen
---->>South America
------->>>Argentina
---->>North America
------->>>ChicagoScreen
------->>>VegasScreen
---->>Europe

And the script should repeat until it's gone through all of the XML files with <AddScreen> or <OnClick> tags.

Can any one help me find a holistic approach to this problem? I know it's a lot to swallow, but if you could guide me through it with bits of code examples, I would be eternally grateful!

A few questions I have right off the bat:
1. After I find elements like <AddScreen> and <OnClick>, how can I match up things like %Label%::Europe;;$(%)ScreenName$(%)::EuropeHome?
2. How can I find a random XML file in a random folder in a specific directory?
3. How can I keep track of the "levels" so that I can insert "Chicago" into "North America" instead of "South America"?

Any help would be greatly appreciated! Any other, more experienced, approaches would be awesome! Thanks! :D

PLEASE DONT JUST LINK ME TO THE PYTHON DOCUMENTATION OR TO "DIVE INTO PYTHON". I've read through both of those - I am looking for ideas and more specialized help.

Recommended Answers

All 3 Replies

Thank you, but I'm looking to do this without any additional modules. My script will be deployed on many computers and I don't want my users to have to install Python+another module separately.

Any other suggestions are welcome.

There are no aditional modules there.

You can even use the cElementTree module also included on python.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.