Python 3.x 解析Tableau xml不保留原始文件
我尝试以编程方式处理Tableau桌面文件(尽管扩展名为.twb,但它只是xml文件)。我对lxml有很多问题,它不能保留原始内容。为了便于解释,假设您有一个test.xml文件,其中包含以下文本:Python 3.x 解析Tableau xml不保留原始文件,python-3.x,lxml,Python 3.x,Lxml,我尝试以编程方式处理Tableau桌面文件(尽管扩展名为.twb,但它只是xml文件)。我对lxml有很多问题,它不能保留原始内容。为了便于解释,假设您有一个test.xml文件,其中包含以下文本: <column caption='Choix Découpage' name='[Aujourd'Hui Parameter (copy 2)]'> <member name='Nb d'annulations' default
<column caption='Choix Découpage' name='[Aujourd'Hui Parameter (copy 2)]'>
<member name='Nb d'annulations' default-format='n#,##0.00" annulations";-#,##0.00" annulations"' />
<run> :</run>
<calculation formula='iif([FAC_TYPE] = 'Avoir' , [Calculation_1378101492427309057], null)' />
<alias key='"Billetterie Ferroviaire"' value='Train ticketing' />
</column>
运行代码时,我们会注意到:
变为”
“
变为é
编辑:此部分已解决和#233;
变为&apos;
”
[node.attrib['key'] for node in root.xpath("//alias")]
我得到的结果是:
['“Billetterie Ferroviaire”']
如果我正在查找属性“key”是原始“Billetterie Ferroviaire”
(root.xpath('/[@key=“Billetterie Ferroviaire”])
不起作用的节点,我现在无法使用xpath进行查询)刚刚编辑,网站直接解释了字符,就XML而言,和&&233;
是完全一样的。您的XML没有改变。
[node.attrib['key'] for node in root.xpath("//alias")]