2

I can find elements but i want get the value of the tag This is my xml file.

<?xml version="1.0" encoding="UTF-8"?><BusinessTransactions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Controller="http://10.43.11.143:8090/controller/rest" GenerationTime="2015-12-30T09:47:46.817698-03:00" xsi:noNamespaceSchemaLocation="bt_metrics.xsd"> 
 <BusinessTransaction>
<ApplicationName>Portales</ApplicationName>
<BusinessTransactionName>APP</BusinessTransactionName>
<AverageResponseTime>142</AverageResponseTime>      
<CallsPerMinute>169</CallsPerMinute>
<ErrorsPerMinute>15</ErrorsPerMinute>

and my code

from xml.dom.minidom import parse, parseString
from xml.dom import minidom
dom = parse("data.xml")
for node in dom.getElementsByTagName('CallsPerMinute'): 
print node.toxml()

1 Answer 1

3

You need to use the firstChild.nodeValue in order to get the value of the node:

from xml.dom.minidom import parse

dom = parse("data.xml")
for node in dom.getElementsByTagName('CallsPerMinute'):
    print(node.firstChild.nodeValue)

Also, your xml needs your tags closed:

<?xml version="1.0" encoding="UTF-8"?>
<BusinessTransactions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      Controller="http://10.43.11.143:8090/controller/rest"
                      GenerationTime="2015-12-30T09:47:46.817698-03:00" xsi:noNamespaceSchemaLocation="bt_metrics.xsd">
    <BusinessTransaction>
        <ApplicationName>Portales</ApplicationName>
        <BusinessTransactionName>APP</BusinessTransactionName>
        <AverageResponseTime>142</AverageResponseTime>
        <CallsPerMinute>169</CallsPerMinute>
        <ErrorsPerMinute>15</ErrorsPerMinute>
    </BusinessTransaction>
</BusinessTransactions>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.