# -*- 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