python - Access xml element attribute with <!..> -


this question has answer here:

i want write small program read data xml file , write csv. work element tree.

the xml files have origin in application mobile phones , this:

<waypoint><name><![cdata[poi 2017-07-03 09:37:11nass]]></name>  <coord lat="47.220430" lon="8.951071"/></waypoint> 

i not have problem access coord-root , content (longitude , latitude). how can access information of name: [cdata[poi 2017-07-03 09:37:11nass]]?

my code looks far:

for poi in pois:     tree = etree.parse(rootwayp + poi)     root = tree.getroot()     child in root:         childchild in child:             print(childchild.tag, ':', childchild.attrib) 

i think need implement reading method name-content, bracket not include information there. have tried access information subchild of name, not work (maybe because of ! in brackets?) ! in <!...> mean?

the <![cdata[...]]> special marked section

you can use following selectors extract details need :

root = tree.getroot()  print(root.find('name').text) print(root.find('coord').attrib.get('lat','n/a')) print(root.find('coord').attrib.get('lon','n/a'))  # output poi 2017-07-03 09:37:11nass 47.220430 8.951071 

with lxml, can extract whole cdata section, here doc about.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -