On Sep 4, 3:18 pm, "Edward K. Ream" <[email protected]> wrote:
> On Sep 4, 3:09 pm, Terry Brown <[email protected]> wrote:
>
> > w/o xpath, it's somehow search for the element with @id='co_text_holder', 
> > and then somehow find its parent.
>
> How about this? ::

That computes parents.  The first step in associating ids with
elements is::

def getId(e):
    return id(e)

ids = {}
def computeIds(d,e):
    i = getId(e)
    if i: d[i] = e
    for child in e.getchildren():
        computeIds(d,child)

for key in ids.keys():
    val = ids.get(key)
    print('id: %9s element: %9s' % (key,val))

Of course, getId is wrong.  But its fine for prototyping.  So we're
close.

So now, given an element e, we need only find it's id attribute. But
that is easy:

def getId(e):
    return e.attrib.get('id')

To test, we do:

names = (
    "co_bc_1",        # 1 digit black circle
    "co_bc_2",        # 2 digit black circle
    "co_bc_text_1",   # text holder for 1 digit black circle
    "co_bc_text_2",   # text holder for 2 digit black circle
    "co_frame",       # frame for speech balloon callout
    "co_g_bc_1",      # group for 1 digit black circle
    "co_g_bc_2",      # group for 2 digit black circle
    "co_g_co",        # group for speech balloon callout
    "co_shot",        # image for screen shot
    "co_text_holder", # text holder for speech balloon callout
)

for name in names:
    print(name,ids.get(name))

Now how hard was that?

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to