According to this post , I successfully can parse my XML file, and reading it's content. However, if I add namespace to it, the whole thing goes wrong.
Let's consider the following XML:
<root xmlns="MyNamespace">
<A1>
<B1></B1>
<C>1<D1></D1></C>
<E1></E1>
</A1>
<A2>
<B2></B2>
<C>2<D></D></C>
<E2></E2>
</A2>
</root>
My iterparse looks like this:
context = ET.iterparse('../in/process/teszt.xml', events=('end', ), tag='B1')
I found several examples, but to be honest I don't really understand them, and have no idead how to solve this problem.
如果XML具有默认名称空间 ,则需要在tag
使用名称空间URI以及元素的本地名称:
context = ET.iterparse('../in/process/teszt.xml', events=('end', ), tag='{MyNamespace}B1')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.