News for hackers. Stuff that matters.
Re:Apple, in Sign of Health Ambitions, Adds Medical Records ... by mercutio2 on Wednesday January 24, 2018 @09:07PM (#16228223)
Why are you using regular expressions to parse XML? Python has excellent XML libraries.
Re:Apple, in Sign of Health Ambitions, Adds Medical Records ... by minimaxir on Thursday January 25, 2018 @12:57AM (#16229076)
Because reading line-by-line is better than loading-and-parsing a 1 GB (in my case) XML file.
Re:Apple, in Sign of Health Ambitions, Adds Medical Records ... by icebraining on Thursday January 25, 2018 @02:07AM (#16229319)
Iterative parsing is your friend: http://boscoh.com/programming/reading-xml-serially.html

There used to be a big argument between DOM and SAX parsers, but iterative/streaming parsers nowadays offer a pretty good compromise.

Re:Apple, in Sign of Health Ambitions, Adds Medical Records ... by mercutio2 on Thursday January 25, 2018 @10:22AM (#16231339)
That link has some bizarre misconceptions about namespaces (just define the namespace URLs you’re interested in as constants, don’t depend on the particular short name/URL map you expect, as that guy does).

It also looks like it predates cElementTree, which has an identical API but is vastly faster.

But anyway, yes, iterparse will be much more reliable/flexible than a regular expression search of non-canonical XML data, and will likely be faster, too.