How To Add A Root To An Existing Xml Which Doesn't Have A Single Root Tag
I'm having one XML file which doesn't have a single root tag. I want to add a new Root tag to this XML file. Below is the existing XML: 123 &l
Solution 1:
from xml.etreeimportElementTreeasET
node = ET.parse(Input_FilePath)
xml.etree.ElementTree.ParseError: junk after documentelement: line 4, column 0
You'll need to read the file manually and add the tags yourself:
from xml.etree import ElementTree as ET
withopen(Input_FilePath) as f:
xml_string = '<X>' + f.read() + '</X>'
node = ET.fromstring(xml_string)
Post a Comment for "How To Add A Root To An Existing Xml Which Doesn't Have A Single Root Tag"