I have a large XML file representing text. Page tags contain line tags, line tags contain individual-char tags, each with many attributes.
I'm trying to correct this and need to insert new char tags at places between existing ones.
I have a valid char Tag - at least PyDev tells me it's is, called insertTag, and I'm trying to insert a new char tag after it.
insertTag.insertAfter(aCopy)
This throws "TypeError: 'NoneType' object is not callable"
I save the actual parse tree Tag as a value in a python list, and assign it to insertTag. But it points to a soup Tag object.
aCopy is a deep copy made from a nearby char tag as a template, which I then change. In case it needs to be in the parse tree before the insert, I've also tried
inserting soup.new_tag(aCopy) which gives the same error.
This happens the first time, not an edge case.
Here's the real code
insertTag = aList[aStart + common - 1] # insertion point, insert after this
for i in range(common, pLen):
# Clone the last existing tag
aCopy = copy.copy(aList[aStart + common - 1])
aCopy.string = pSub[i] # change the string contents
aCopy['added'] = 1 # mess about with attributes
## at this point, insertTag and aCopy are both of type Tag
insertTag.insertAfter(aCopy) # throws TypeError
insertTag = aCopy # next insert goes after this one
In short, I have an apparently valid tag from a soup document, and I can't insert another apparently valid tag after it. What am I doing wrong?