M
mirandacascade
I do not understand how to use the find() method in ElementTree.
The file 'sample.xml' is:
<?xml version="1.0"?>
<SampleRoot>
<Header>
<Product>FindMystery</Product>
</Header>
<SpecificInformation>
<SampleDetail>abc</SampleDetail>
</SpecificInformation>
[<Element SampleRoot at 1166850>, <Element Header at 1166878>, <Element
....
x is none
The ElementTree documentation indicates that:
"find(pattern) returns the first subelement that matches the given
pattern, or None if there is no matching element."
and
"the pattern argument can either be a tag name, or a path expression"
Based on the following snippet from the interactive window:
I inferred (perhaps incorrectly) that within doc there is a subelement
with a tag 'SampleDetail'.
Based on the following snippet:
.... print 'x is none'
....
x is none
I conclude that there is no subelement in doc with a tag
'SampleDetails'.
My questions:
1) in the example above is there a subelement of doc with a tag
'SampleDetails'?
2) if so, what is the proper way of writing the call to the find()
method to locate that subelement?
The file 'sample.xml' is:
<?xml version="1.0"?>
<SampleRoot>
<Header>
<Product>FindMystery</Product>
</Header>
<SpecificInformation>
<SampleDetail>abc</SampleDetail>
</SpecificInformation>
[<Element SampleRoot at 1166850>, <Element Header at 1166878>, <Element
.... print 'x is none'<Element said:len(iterList) 5
element = iterList[4]
element.tag 'SampleDetail'
x = doc.find('SampleDetail')
if x == None:
....
x is none
The ElementTree documentation indicates that:
"find(pattern) returns the first subelement that matches the given
pattern, or None if there is no matching element."
and
"the pattern argument can either be a tag name, or a path expression"
Based on the following snippet from the interactive window:
'SampleDetail'doc = ElementTree(file='sample.xml')
iterList = doc.getiterator()
element = iterList[4]
element.tag
I inferred (perhaps incorrectly) that within doc there is a subelement
with a tag 'SampleDetail'.
Based on the following snippet:
.... print 'x is none'
....
x is none
I conclude that there is no subelement in doc with a tag
'SampleDetails'.
My questions:
1) in the example above is there a subelement of doc with a tag
'SampleDetails'?
2) if so, what is the proper way of writing the call to the find()
method to locate that subelement?