Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python属性解析为xml:id返回无_Python_Python 3.x_Xml Parsing_Attributes_Elementtree - Fatal编程技术网

Python属性解析为xml:id返回无

Python属性解析为xml:id返回无,python,python-3.x,xml-parsing,attributes,elementtree,Python,Python 3.x,Xml Parsing,Attributes,Elementtree,我正在尝试使用以下代码从tei文件中提取一些信息: tree = ET.parse(path) root = tree.getroot() body = root.find("{http://www.tei-c.org/ns/1.0}text/{http://www.tei-c.org/ns/1.0}body") for s in body.iter("{http://www.tei-c.org/ns/1.0}s"): for w in s.iter("{http://www.tei

我正在尝试使用以下代码从tei文件中提取一些信息:

tree = ET.parse(path)
root = tree.getroot()
body = root.find("{http://www.tei-c.org/ns/1.0}text/{http://www.tei-c.org/ns/1.0}body")  
for s in body.iter("{http://www.tei-c.org/ns/1.0}s"):
    for w in s.iter("{http://www.tei-c.org/ns/1.0}w"):
        wordpart = w.find("{http://www.tei-c.org/ns/1.0}seg")
        word = ''.join(wordpart.itertext())
        type = w.get('type')
        xml = w.get('xml:id') 
        print(type)             
        print(xml)
类型
的输出是正确的,它打印例如“noun”。但是对于
xml:id
我只能得到
None
。这是我需要解析的xml文件的摘录:

<w type="noun" xml:id="w.4940"><seg type="orth">sloterheighe</seg>...
sloterheighe。。。

要获取
xml:id
属性的值,需要像这样指定名称空间URI(有关更多详细信息,请参阅):


另外,请注意,
type
是Python中的内置方法,因此请避免将其用作变量名。

为什么
xml:id=“w.4940”“
末尾有两个引号?小错误,我编辑了它,谢谢
xml = w.attrib['{http://www.w3.org/XML/1998/namespace}id']
xml = w.get('{http://www.w3.org/XML/1998/namespace}id')