我試圖使用以下代碼檢索'a:t'標籤之間的類型=「slidenum」之間的幻燈片編號,但某些內容不起作用。我應該得到1從xml標籤中檢索數據Python
這裏的XML:
<a:p><a:fld id="{55FBEE69-CA5C-45C8-BA74-481781281731}" type="slidenum">
<a:rPr lang="en-US" sz="1300" i="0"><a:solidFill><a:srgbClr val="000000"/>
</a:solidFill></a:rPr><a:pPr/><a:t>1</a:t></a:fld><a:endParaRPr lang="en-US"
sz="1300" i="0"><a:solidFill><a:srgbClr val="000000"/></a:solidFill>
</a:endParaRPr></a:p></p:txBody></p:sp>
這裏是我的代碼
z = zipfile.ZipFile(pptx_filename)
for name in z.namelist():
m = re.match(r'ppt/notesSlides/notesSlide\d+\.xml', name)
if m is not None:
f = z.open(name)
tree = ET.parse(f)
f.close()
root = tree.getroot()
# Find the slide number.
slide_num = None
for fld in root.findall('/'.join(['.', '', p.txBody, a.p, a.fld])):
if fld.get('type', '') == 'slidenum':
slide_num = int(fld.find(a.t).text)
print slide_num
您能編輯問題以包含XML嗎?我認爲這對我們有很大的幫助:)在評論 – Jerfov2
'a:'中很難閱讀它,這意味着這些元素都在XML命名空間中。搜索這些標籤時可能需要包含名稱空間。如果你不確定如何做,你應該檢查這個答案:http://stackoverflow.com/a/14853417/849425 –