Skip to main content
Tweeted twitter.com/#!/StackCodeReview/status/328148074159538177
added 33 characters in body
Source Link

I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated.

# This is only part of XML examplethat interesting me:
# <skill>
#   <id>14</id>
#   <skill>
#     <name>C++</name>
#   </skill>
# </skill>
# <skill>
#   <id>15</id>
#   <skill>
#     <name>Java</name>
#   </skill>
# </skill>

skills = document.getElementsByTagName('skill')

for skill in skills:
    try:
        id_ = skill.getElementsByTagName('id')[0].firstChild.nodeValue
        name = skill.getElementsByTagName('name')[0].firstChild.nodeValue

        my_object.create(name=name.strip(),
                         id=id_.strip())
    except IndexError:
        pass

I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated.

# XML example:
# <skill>
#   <id>14</id>
#   <skill>
#     <name>C++</name>
#   </skill>
# </skill>
# <skill>
#   <id>15</id>
#   <skill>
#     <name>Java</name>
#   </skill>
# </skill>

skills = document.getElementsByTagName('skill')

for skill in skills:
    try:
        id_ = skill.getElementsByTagName('id')[0].firstChild.nodeValue
        name = skill.getElementsByTagName('name')[0].firstChild.nodeValue

        my_object.create(name=name.strip(),
                         id=id_.strip())
    except IndexError:
        pass

I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated.

# This is only part of XML that interesting me:
# <skill>
#   <id>14</id>
#   <skill>
#     <name>C++</name>
#   </skill>
# </skill>
# <skill>
#   <id>15</id>
#   <skill>
#     <name>Java</name>
#   </skill>
# </skill>

skills = document.getElementsByTagName('skill')

for skill in skills:
    try:
        id_ = skill.getElementsByTagName('id')[0].firstChild.nodeValue
        name = skill.getElementsByTagName('name')[0].firstChild.nodeValue

        my_object.create(name=name.strip(),
                         id=id_.strip())
    except IndexError:
        pass
Source Link

Parsing XML with double nested tags using mindom

I want to retrieve id and name per skill. It works but is it well done? I would like to stay with minidom but all advices will be appreciated.

# XML example:
# <skill>
#   <id>14</id>
#   <skill>
#     <name>C++</name>
#   </skill>
# </skill>
# <skill>
#   <id>15</id>
#   <skill>
#     <name>Java</name>
#   </skill>
# </skill>

skills = document.getElementsByTagName('skill')

for skill in skills:
    try:
        id_ = skill.getElementsByTagName('id')[0].firstChild.nodeValue
        name = skill.getElementsByTagName('name')[0].firstChild.nodeValue

        my_object.create(name=name.strip(),
                         id=id_.strip())
    except IndexError:
        pass