【发布时间】:2020-02-15 18:52:22
【问题描述】:
我在我的 oracle 数据库中将此 xml 保存为 CLOB:
<?xml version="1.0" encoding="UTF-8"?>
<DCResponse>
...
</DCResponse>
使用这个 python 代码,我可以将内容保存到 xml 文件中:
sql = "select extract(xmltype.createxml(xml), '//DCResponse').getStringVal() from table t where id = 2"
for row in cursor.execute(sql):
print(row[0])
with open("output.xml", "w") as f:
f.write(row[0])
用这个xml代替
<?xml version="1.0" encoding="ISO-8859-1"?>
<PIPEDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XML-PIPE
PIPEDocument.xsd" ReferenceNumber="567862650" CreationDate="20200115155255" Version="1.0"
xmlns="urn:XML-PIPE">
...
</PIPEDocument>
我无法使用 python 提取内容。 Write() 参数必须是 str,而不是 None .....是 Python 控制台运行此代码的结果:
sql = "select extract(xmltype.createxml(xml), '//PIPEDocument').getStringVal() from table t where id
= 7"
for row in cursor.execute(sql):
print(row[0])
with open("output.xml", "w") as f:
f.write(row[0])
在我的 oracle 客户端中,python 中使用的以下 sql 查询的输出为空:
select extract(xmltype.createxml(xml), '//PIPEDocument').getStringVal() from table t where id = 7;
当 xml 内容存在于我的数据库中时:
select xml from table where id =7
不确定是什么问题,可能是选择查询中的关键字“//PIPEDocument”或两个 XML 文件之间的编码不同,但不知道如何解决。
请帮忙 最好的祝福 詹卡洛
【问题讨论】: