Python Forum
[XML] How to add new element to block?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[XML] How to add new element to block?
#1
Hello,

Using BeautifulSoup, I can't figure out how to add a new element to the current block:

from bs4 import BeautifulSoup as Soup with open('track.kml') as data: kml_soup = Soup(data, 'lxml-xml') # Parse as XML placemarks = kml_soup.find_all('Placemark') for pm in placemarks:	if pm.find('LineString'):	print("LS found")	#How to insert new element before LineString?	#TypeError: 'NoneType' object is not callable	tag = pm.new_tag("Blah")	tag.string = "<Another>blah</Another>"	pm.string.insert_after(tag)	print(pm)
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to locate element no such element gahhon 6 6,697 Feb-18-2019, 02:09 PM
Last Post: gahhon
  Change single element in 2D list changes every 1D element AceScottie 9 15,769 Nov-13-2017, 07:05 PM
Last Post: Larz60+

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.