相关疑难解决方法(0)

使用saxon和python

我需要使用python处理XSLT,目前我正在使用仅支持XSLT 1的lxml,现在我需要处理XSLT 2有没有办法在python中使用saxon XSLT处理器?

python xslt saxon xslt-2.0

6
推荐指数
4
解决办法
6277
查看次数

使用Python Scrape XML文件

我一直试图刮取XML文件来复制2个标签的内容,仅限代码和源代码.xml文件如下所示:

<Series xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RunDate>2018-06-12</RunDate>
  <Instruments>
    <Instrument>
      <Code>27BA1</Code>
      <Source>YYY</Source>
    </Instrument>
    <Instrument>
      <Code>28BA1</Code>
      <Source>XXX</Source>
    </Instrument>
      <Code>29BA1</Code>
      <Source>XXX</Source>
    </Instrument>
      <Code>30BA1</Code>
      <Source>DDD</Source>
    </Instrument>
  </Instruments>
</Series>
Run Code Online (Sandbox Code Playgroud)

我只是抓住了第一个代码.下面是代码.有人可以帮忙吗?

import xml.etree.ElementTree as ET
import csv

tree = ET.parse("data.xml")
csv_fname = "data.csv"
root = tree.getroot()

f = open(csv_fname, 'w')
csvwriter = csv.writer(f)
count = 0
head = ['Code', 'Source']

csvwriter.writerow(head)

for time in root.findall('Instruments'):
    row = []
    job_name = time.find('Instrument').find('Code').text
    row.append(job_name)
    job_name_1 = time.find('Instrument').find('Source').text
    row.append(job_name_1)
    csvwriter.writerow(row)
f.close()
Run Code Online (Sandbox Code Playgroud)

python xml csv parsing

1
推荐指数
1
解决办法
1275
查看次数

标签 统计

python ×2

csv ×1

parsing ×1

saxon ×1

xml ×1

xslt ×1

xslt-2.0 ×1