This is a memo on how to set the xml:id attribute with BeautifulSoup.
The following method causes an error.
from bs4 import BeautifulSoup
soup = BeautifulSoup(features="xml")
soup.append(soup.new_tag("p", abc="xyz", xml:id="abc"))
print(soup)
Writing it as follows works correctly.
from bs4 import BeautifulSoup
soup = BeautifulSoup(features="xml")
soup.append(soup.new_tag("p", **{"abc": "xyz", "xml:id":"aiu"}))
print(soup)
An execution example on Google Colab is available below.
https://github.com/nakamura196/ndl_ocr/blob/main/BeautifulSoupでxml_id属性を与える方法.ipynb
We hope this is helpful.