Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to read data from xml file
#6
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 13 20:33:17 2018

@author: user
"""

#from xml.dom import minidom
#
#doc = minidom.parse("D:\Mekala_Backupdata\PythonCodes\input.xml")

 
#import xml.etree.cElementTree as ET
#tree = ET.ElementTree('D:\Mekala_Backupdata\PythonCodes\input.xml')
#root = tree.getroot()
#for books in root:
#    if (books.tag=='book'):
#        print books.get('id')
#        for attr in books:
#            if (attr.tag=='author'):
#                print (attr.text)
                
import xml.etree.cElementTree as ET
source_file = 'D:\Mekala_Backupdata\PythonCodes\input.xml'
tree = ET.parse(source_file)
root = tree.getroot()
for books in root:
    if (books.tag=='book'):
        print(books.get('id'))
        for attr in books:
            if (attr.tag=='author' or attr.tag=='title' or attr.tag=='price'):
                print (attr.text)
the code is workig,
But in tilte part, I only want first part before ":"

for example: in my above xml file the last title is:
Visual Studio 7: A Comprehensive Guide
I only want upto "Visual Studio 7" (or if I want to take the part after ":" i.e A Comprehensive Guide)

kinldy help how to do this
Reply


Messages In This Thread
how to read data from xml file - by Raj - Apr-13-2018, 02:21 PM
RE: how to read data from xml file - by dwill - Apr-13-2018, 04:09 PM
RE: how to read data from xml file - by Larz60+ - Apr-13-2018, 08:18 PM
RE: how to read data from xml file - by Raj - Apr-14-2018, 05:26 AM
RE: how to read data from xml file - by dwill - Apr-14-2018, 06:39 AM
RE: how to read data from xml file - by Raj - Apr-14-2018, 10:31 AM
RE: how to read data from xml file - by snippsat - Apr-14-2018, 11:49 AM
RE: how to read data from xml file - by Raj - Apr-14-2018, 12:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open and read a tab delimited file from html using python cgi luffy 2 2,687 Aug-24-2020, 06:25 AM
Last Post: luffy
  Read owl file using python flask Gayathri 1 2,466 Nov-20-2019, 12:56 PM
Last Post: ChislaineWijdeven
  Read XML-File yuyu 16 7,176 Dec-15-2018, 10:49 PM
Last Post: snippsat
  Read input file and print hyperlinks Emmanouil 8 15,242 Oct-23-2016, 07:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020