Quantcast
Viewing all articles
Browse latest Browse all 14011

get the child element of from the xml

I have an XML where I want to get the child elements of the elements where my condition is satisfied.

<hashTree/><ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true"><elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"><collectionProp name="Arguments.arguments"/></elementProp><stringProp name="HTTPSampler.domain"></stringProp><stringProp name="HTTPSampler.port"></stringProp><stringProp name="HTTPSampler.protocol">https</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path"></stringProp><stringProp name="HTTPSampler.concurrentPool">6</stringProp><stringProp name="HTTPSampler.connect_timeout"></stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></ConfigTestElement><hashTree/><CacheManager guiclass="CacheManagerGui" testclass="CacheManager" testname="HTTP Cache Manager" enabled="true"><boolProp name="clearEachIteration">false</boolProp><boolProp name="useExpires">true</boolProp></CacheManager><hashTree/><CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="HTTP Cookie Manager" enabled="true"><collectionProp name="CookieManager.cookies"/><boolProp name="CookieManager.clearEachIteration">true</boolProp></CookieManager><hashTree/><kg.apc.jmeter.threads.SteppingThreadGroup guiclass="kg.apc.jmeter.threads.SteppingThreadGroupGui" testclass="kg.apc.jmeter.threads.SteppingThreadGroup" testname="/v1/language-preferences__GET" enabled="true"><stringProp name="ThreadGroup.on_sample_error">startnextloop</stringProp><stringProp name="ThreadGroup.num_threads">2</stringProp><stringProp name="Threads initial delay">0</stringProp><stringProp name="Start users count">1</stringProp><stringProp name="Start users count burst">1</stringProp><stringProp name="Start users period">75</stringProp><stringProp name="Stop users count">1</stringProp><stringProp name="Stop users period">75</stringProp><stringProp name="flighttime">3600</stringProp><stringProp name="rampUp">75</stringProp><elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"><boolProp name="LoopController.continue_forever">false</boolProp><intProp name="LoopController.loops">-1</intProp></elementProp></kg.apc.jmeter.threads.SteppingThreadGroup><hashTree>

above I want to get the value of <stringProp name="ThreadGroup.num_threads">2</stringProp> which is the chile element of kg.apc.jmeter.threads.SteppingThreadGroup also attribute @enabled="true".

I can filter out the required elements with the below code.

tree = ET.parse(xml_path)active_threads = tree.findall('.//kg.apc.jmeter.threads.SteppingThreadGroup[@enabled="true"]' or './/ThreadGroup[@enabled="true"]')

now I want to iterate within the each thread from the active_threads and get the child elements.something like

    for active_thread in active_threads:        thread_name.append(active_thread.attrib['testname'])        for child in thread.getchildren():            print(child['@name'])            # <print the value as well against each child like for "ThreadGroup.num_threads" is 2 >

Viewing all articles
Browse latest Browse all 14011

Trending Articles