作動しないI 2つのXMLノードの値を変更したい - SET_STATUS FILEDATAがに存在するこのXML列ことがテキストであるためパイソン - 正規表現を持つ2つのノード間の更新XML値 - re.subは
<ws:genericAction>SET_STATUS</ws:genericAction>
。それは、正規表現を書いた:
re.sub(r'<\/ws:genericAction>\s*(.*)(?=\n<\/ws:genericAction>)', "New Text", filedata, flags=re.IGNORECASE)
すべてのプログラム:あなたのための
with open("createUser.txt", 'r') as file:
filedata = file.read()
re.sub(r'<\/ws:genericAction>\s*(.*)(?=\n<\/ws:genericAction>)', "New Text", filedata, flags=re.IGNORECASE)
with open("createUser.txt", 'w') as file:
file.write(filedata)
感謝を
filedata = re.sub(r'(<ws:genericAction>)([^<>]+)(?=<\/ws:genericAction>)', "\\1New Text", filedata, flags=re.IGNORECASE)
https://docs.python.org/3/library/re.html#re.sub
パーサーを使用します(例: 'lxml'。 – Jan