Python の etree.ElementTree パッケージを使用して xml ファイルを解析しましたが、失敗しているようです。
私のxmlファイル階層は次のようになっています: root <- -> config data <> sourcefile <- -> file object1 object2 ...など.
print self.xml_root.findall(".\config") を使用すると、空のリストである "[]" しか取得できませんでした。
Python の etree.ElementTree パッケージを使用して xml ファイルを解析しましたが、失敗しているようです。
私のxmlファイル階層は次のようになっています: root <- -> config data <> sourcefile <- -> file object1 object2 ...など.
print self.xml_root.findall(".\config") を使用すると、空のリストである "[]" しか取得できませんでした。
本当に'.\config'
文字列を持っている場合、それが問題になります。\c
これは、文字の1 つとして使用する文字列リテラルです。'.\\config'
またはr'.\config'
があり、どちらもリテラルのバックスラッシュを指定している場合でも、それはまだ間違っています。
$ cat eleme.py
import xml.etree.ElementTree as ET
root = ET.fromstring("""
<root>
<config>
source
</config>
<config>
source
</config>
</root>""")
print r'using .\config', root.findall('.\config')
print r'using .\\config', root.findall('.\\config')
print 'using ./config', root.findall('./config')
$ python2.7 eleme.py
using .\config []
using .\\config []
using ./config [<Element 'config' at 0x8017a8610>, <Element 'config' at 0x8017a8650>]