0

The following code:

import xml.etree.ElementTree as ET

essai = '''<?xml version='1.0' standalone='yes' ?>
<LVData xmlns="http://www.ni.com/LVData">
<Version>18.0.1f4</Version>
<Cluster>
<Name>Out</Name>
<NumElts>34</NumElts>
<DBL>
<Name>Amplitude_Signal</Name>
<Val>0.30000000000000</Val>
</DBL>
</Cluster>
</LVData>'''          

root = ET.fromstring(essai)
for child in root[1]:
    print(child.tag, child.attrib)

produces empty attribute results:

{http://www.ni.com/LVData}Name {}
{http://www.ni.com/LVData}NumElts {}
{http://www.ni.com/LVData}DBL {}

Why?

8
  • As opposed to what - what was the expected outcome? Commented Sep 3 at 12:41
  • An XML attribute is <a key="value">element text</a> key in this case. The elements in the sample have no attributes. Commented Sep 3 at 12:41
  • <Name>Amplitude_Signal</Name> That element has no attributes. What were you expecting? "Amplitude_Signal" is the text, not an attribute. Commented Sep 3 at 12:43
  • Duplicate of stackoverflow.com/questions/35683790/… Commented Sep 3 at 12:50
  • Well, wait a bit, "<DBL> <Name>Amplitude_Signal</Name> <Val>0.30000000000000</Val> </DBL>" contain two fields, how to acces it? Commented Sep 3 at 13:01

1 Answer 1

1

In <Name>Amplitude_Signal</Name>, I was thinking that Amplitude_Signal was the attribute.

This is only the "text".

So

child.attribute

should be replaced by:

child.text

returning

{http://www.ni.com/LVData}Name Out
{http://www.ni.com/LVData}NumElts 34
{http://www.ni.com/LVData}DBL 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.