Hi Martin, unique IDs are written into the constraints in the XML specification itself (in 3.3.1, Attribute types).
However, you can tell the XML parser to not care about IDs. I’m not sure if this is a useful option. With renaming, processing and renaming back you know at least exactly what is going on. if you have a document like this: >>> from lxml import etree >>> >>> s = '<a><b xml:id="id1"/><c xml:id="id1"/></a>' >>> containing the same ID twice, this fails: >>> etree.XML(s) Traceback (most recent call last): … lxml.etree.XMLSyntaxError: ID id1 already defined, line 1, column 36 But I can define a parser with the option collect_ids set to false, like this: >>> myparser = etree.XMLParser(collect_ids=False) use it to parse my document s: >>> tree = etree.XML(s, parser=myparser) and everything seems fine: >>> etree.dump(tree) <a> <b xml:id="id1"/> <c xml:id="id1"/> </a> >>> As I said, this is a path not often taken, proceed with caution. jens > On 31. Jul 2022, at 23:56, Martin Mueller <martinmuel...@northwestern.edu> > wrote: > > Duplicate xmlids have way of creeping into my 60,000 documents. The ids keep > the document from parsing, which is helpful in drawing attention to errors, > but it makes it harder to correct the errors. I work with documents in the > TEI namespace, and I have a very kludgy workaround: I comment out the > reference to the schema and change ‘xml:id ‘ to ‘xmlom’. Then I can loop > through the document and fix errors with a script. > > There must be a more elegant way to do this. Is there away of telling lxml: > “never mind the duplicate IDs. Just carry on”. Then I can toggle between a > script that cares or doesn’t care about duplicate IDS. > > With thanks in advance for any help > > Martin Mueller > Professor emeritus of English and Classics > Northwestern University > > > _______________________________________________ > lxml - The Python XML Toolkit mailing list -- lxml@python.org > <mailto:lxml@python.org> > To unsubscribe send an email to lxml-le...@python.org > <mailto:lxml-le...@python.org> > https://mail.python.org/mailman3/lists/lxml.python.org/ > <https://mail.python.org/mailman3/lists/lxml.python.org/> > Member address: j...@qdevelop.de <mailto:j...@qdevelop.de>
_______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-le...@python.org https://mail.python.org/mailman3/lists/lxml.python.org/ Member address: arch...@mail-archive.com