Jun-07-2019, 04:06 PM
(Jun-06-2019, 04:41 AM)heiner55 Wrote:#!/usr/bin/python3 import xml.etree.ElementTree as ET . file = ET.parse(r'test.xml') . for node in file.getroot(): print(node) firstname = node.findall('{http://tempuri.org/sdnList.xsd}firstName') print(firstname)
Output:<Element '{http://tempuri.org/sdnList.xsd}publshInformation' at 0xb74ffd24> [] <Element '{http://tempuri.org/sdnList.xsd}sdnEntry' at 0xb74ffdc4> [<Element '{http://tempuri.org/sdnList.xsd}firstName' at 0xb74ffe14>] <Element '{http://tempuri.org/sdnList.xsd}sdnEntry' at 0xb7502554> [<Element '{http://tempuri.org/sdnList.xsd}firstName' at 0xb75025a4>] ... ... ...
Thanks for the answer.
Using the way suggested I manage to parse some data.
import pandas as pd import xml.etree.ElementTree as ET file = ET.parse(r'test.xml') # Create an emplty dataframe Data_columns=['uid','firstName','lastName','sdnType'] table = pd.DataFrame(columns=Data_columns) table = pd.DataFrame() for node in file.getroot(): uid= [uid.text for uid in node.findall('{http://tempuri.org/sdnList.xsd}uid')] firstname= [firstname.text for firstname in node.findall('{http://tempuri.org/sdnList.xsd}firstName')] lastName= [lastName.text for lastName in node.findall('{http://tempuri.org/sdnList.xsd}lastName')] sdnType= [sdnType.text for sdnType in node.findall('{http://tempuri.org/sdnList.xsd}sdnType')] table_List =[[uid,firstname,lastName,sdnType]] table1 = pd.DataFrame(table_List,columns=Data_columns) table = table.append(table1,ignore_index=True) print(table)
Output:Out[37]:
uid firstName lastName sdnType
0 [] [] [] []
1 [9639] [Ismail Abdul Salah] [HANIYA] [Individual]
2 [26182] [Evren] [KAYAKIRAN] [Individual]
How can i get the values with out brackets?Appreciate if someone can help on this