Splitting xml tag in python -


i need split below xml tag using split function in python

<item name="caption" type="string">python</item> 

the split function have used:

output = data.split("<item name=title type=string>")[1].split("</item>")[0] 

for simple tag, can this:

def get_xml_tag_content(tag: str) -> str:     return tag.split('>')[1].split('<')[0]   tag = '<item name="caption" type="string">python</item>' tag_content = get_xml_tag_content(tag)  print(tag_content)  # python 

at first, split our tag the closing > of opening tag, take second element of result, python</item>, , split the opening < of closing tag , take first element, tag's content. (python)


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -