python通过LXML库读取xml命名空间

xml实例版本:


声明命名空间,city为变量,xmlns定义city变量的值。
python 读取输出实例:
        xp=xpxlm.xpath('//node()')
        print xp,           #.items()#.tag
        for i in xp:
            if '' in i or '\n' in i:
                continue
            else: 
                print i.tag

 

输出结果:
{city}table
heilongjiang
{city}haerbin
{city}daqing
guangdong
{city}guangzhou
{city}shenzhen
{city}zhuhai
........

改变city">为


输出结果为:
{a}table
heilongjiang
{a}haerbin
{a}daqing
guangdong
{a}guangzhou
{a}shenzhen
{a}zhuhai
taiwan
{a}taibei
{a}gaoxiong
xinjiang
{a}wulumuqi

 

 







转载于:https://www.cnblogs.com/liuliu-word/p/7498050.html

你可能感兴趣的:(python通过LXML库读取xml命名空间)