在不转换标签的情况下用 BeautifulSoup 解析格式错误的 XML
Parsing badly formed XML with BeautifulSoup without converting tags
BeautifulSoup非常好,可以很简单地修复格式错误的XML:
import bs4
value = unicode(bs4.BeautifulSoup(value, "xml"))
但是在处理这种情况时XML:
<draw:image xlink:href="Pictures/image.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
它给了我:
<image actuate="onLoad" href="Pictures/image.png" show="embed" type="simple"/>
我想保持原样!如何判断BeautifulSoup不要太聪明?
仔细查看整个文档后,我发现一些名称空间定义已不存在。添加它们后,达到了预期的行为。
BeautifulSoup非常好,可以很简单地修复格式错误的XML:
import bs4
value = unicode(bs4.BeautifulSoup(value, "xml"))
但是在处理这种情况时XML:
<draw:image xlink:href="Pictures/image.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
它给了我:
<image actuate="onLoad" href="Pictures/image.png" show="embed" type="simple"/>
我想保持原样!如何判断BeautifulSoup不要太聪明?
仔细查看整个文档后,我发现一些名称空间定义已不存在。添加它们后,达到了预期的行为。