xpath使用小例子

2021-06-09 18:15:51 字數 715 閱讀 5802

要解析的xml檔案(檔名e.xml):

<?xml version="1.0" encoding="iso-8859-1"?>

harry potter

29.99

learning xml

39.95

python指令碼

#!/usr/bin/env python
#coding: utf8
from lxml import etree
from xml.etree import elementtree
read_file = file('e.xml')
lines =
for line in read_file:
read_file.close()
temp_str = ''.join(lines)
root = etree.xml(temp_str)
nodes = root.xpath("//book/title")
for node in nodes:
print node.tag
結果是:
title
title

libiconv使用小例子

最近用到一點轉碼的東西,在網上搜到乙個libiconv,使用了一下感覺還可以,不過還是有一兩處容易犯錯的地方,除錯了半天才搞明白,此處是乙個將utf 8轉換為gbk的小例子 std string convfromutf8 std string s size t inlen s.size const ...

oracle游標使用小例子

游標使用 游標其實是乙個放入記憶體臨時表 declare money cms3 simcard.card fee type 0 定義與表字段相同型別 cursor mycursor is 定義游標 select from cms3 simcard where return flag 1 and ms...

react refetch的使用小例子

出處 react設計模式和最佳實踐 const list const withdata url part componentdidmount render const listwithgists withdata list 上面的 我們將api獲取資料的邏輯用高階元件抽離出來,下面我們再用react...