我正在使用 lxml 来编写 xml 文件。我尝试编写一个根元素,例如:
<Retour xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.cnamts.fr/cereus/fichier/retour/v1"
xsi:schemaLocation="http://www.cnamts.fr/cereus/fichier/retour/v1retour.xsd">
所以我尝试:
NSMAP = {"xsi" : 'http://www.w3.org/2001/XMLSchema-instance'}
retour = ET.Element('Retour', nsmap = NSMAP)
retour.set('xmlns','http://www.cnamts.fr/cereus/fichier/retour/v1')
我得到了:
<Retour xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.cnamts.fr/cereus/fichier/retour/v1">
但我不知道如何设置xsi:schemaLocation="http://www.cnamts.fr/cereus/fichier/retour/v1retour.xsd"
?我有Element.set
一个 unicode 错误。