所以,这是我的游戏计划......
python中的xpath
这是我的xml
所以这个 xml 存储在一个数据库(ca)中,我需要提取这个“数据”来获取所有这些值层并将它们存储到另一个数据库(a):
这是我到目前为止想到的..
import pyodbc
from lxml import etree
from StringIO import StringIO
con_ca = pyodbc.connect(..)
con_a = pyodbc.connect(..)
cur_ca = con_ca.cursor()
cur_c = con_c.cursor()
cur_ca.execute("""
select id_original,data
from table
""")
rows_ca = cur_ca.fetchall()
for row in rows_ca:
id_original = id_original
x = str(row.data)
root = etree.fromstring(x)
BValid = etree.XPath('/Data/Response/Detail/B/Valid')
BPass = etree.XPath('/Data/Response/Detail/B/Pass')
BDetails = etree.XPath('/Data/Response/Detail/B/Details')
BCode = etree.XPath('/Data/Response/Detail/B/Code')
BDecisionS = etree.XPath('/Data/Response/Detail/B/Decision/Result')
BDecisionB = etree.XPath('/Data/Response/Detail/B/Decision/Bucket')
con_a.execute("""
INSERT INTO table2 (id_original,BValid,BPass,BDetails,BCode,BDecisionS BDecisionB)
VALUES(?, ?, ?,?, ?, ?, ?)
""")
.. 一切正常,除了在 fetchall() 之后我能够得到 ('//text') :但是我如何使用 Xpath 进入特定节点以从这个示例中获取值或文本?