Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
xml
#1
Hello everyone,

i'm new to python and i need some help:
I have an xml file:
<Parameter>
<MasterID>1498</MasterID>
<ObjectIDUnique>{C58FB975-5522-411C-9212-F5D81C74E1D1}</ObjectIDUnique>
<Properties dynamic="anonymous">
<Property>
<Name>UID</Name>
<Value>XXXXXX</Value>
</Property>
<Property>
<Name>FID</Name>
<Value>YYYYYY</Value>
</Property>
<Property>
<Name>MODULE</Name>
<Value>ZZZZZZ</Value>
</Property>
<Property>
<Name>A</Name>
<Value>AAAAAA</Value>
</Property>

And i want to recover the value of the tag <ObjectIDUnique> if the "Name" tag contains "UID" and retrieve the "Value" "XXXX" of the "UID" "Name".

Someone can i help me ?
Reply
#2
for param in parameters:


    Properties = param.getElementsByTagName('Property')


    for proper in Properties:
        name = proper.getElementsByTagName("Name")[0].childNodes[0].data
        if name == "UID":
            object_id = param.getElementsByTagName('ObjectIDUnique')[0].childNodes[0].data
            print(f"object_id : {object_id}")
            value = proper.getElementsByTagName("Value")[0].childNodes[0].data
            print(f"value : {value} ")
Gribouillis write Nov-29-2021, 08:13 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020