Python @ DjangoSpin

PyPro #78 Generate XML by surrounding text by a tag name

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Generate XML by surrounding text by a tag name in Python

Generate XML by surrounding text by a tag name in Python

Write a Python program to generate XML by surrounding text by a tag name. For example, generateXML('firstname', 'Ethan') should return '<firstname>Ethan</firstname>'.

Generate XML by surrounding text by a tag name

def generateXML(tagName, contentText):
	return '<{}>{}</{}>'.format(tagName, contentText, tagName)	
	
print(generateXML('firstname', 'Ethan'))	# <firstname>Ethan</firstname>
print(generateXML('lastname', 'Hunt'))		# <lastname>Hunt</lastname>

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply