在python中从ElementTree中删除xml文本

2024-05-14 09:21:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从一个XML文档中提取一个转义符noded。节点的原始文本如下所示:

<Notes>{&quot;Phase&quot;: 0, &quot;Flipper&quot;: 0, &quot;Guide&quot;: 0,     
&quot;Sample&quot;: 0, &quot;Triangle8&quot;: 0, &quot;Triangle5&quot;: 0,     
&quot;Triangle4&quot;: 0, &quot;Triangle7&quot;: 0, &quot;Triangle6&quot;: 0,     
&quot;Triangle1&quot;: 0, &quot;Triangle3&quot;: 0, &quot;Triangle2&quot;: 0}</Notes> 

我将按如下方式拉出文本:

infile = ET.parse("C:/userfiles/EXP011/SESAME_60/SESAME_60_runinfo.xml")
r = infile.getroot()
XMLNS = "{http://example.com/foo/bar/runinfo_v4_3}"
x=r.find(".//"+XMLNS+"Notes")
print(x.text)

我希望得到:

{"Phase": 0, "Flipper": 0, "Guide&quot": 0,     
"Sample": 0, "Triangle8": 0, "Triangle5": 0,     
"Triangle4": 0, "Triangle7": 0, "Triangle6": 0,     
"Triangle1": 0, "Triangle3": 0, "Triangle2": 0}

但是,相反,我得到了:

 {&quot;Phase&quot;: 0, &quot;Flipper&quot;: 0, &quot;Guide&quot;: 0,      
 &quot;Sample&quot;: 0, &quot;Triangle8&quot;: 0, &quot;Triangle5&quot;: 0,   
 &quot;Triangle4&quot;: 0, &quot;Triangle7&quot;: 0, &quot;Triangle6&quot;: 0, 
 &quot;Triangle1&quot;: 0, &quot;Triangle3&quot;: 0, &quot;Triangle2&quot;: 0}

如何获取未转义的字符串?


Tags: sample文本guidenotesflipperquotphasetriangle7

热门问题