REXML Language Identification monkey patch


/ Published in: Ruby
Save to your folder(s)

REXML does not seem to have a 'lang' method, which is strange since lang is in the XML 1.0 Specification §2.12 'Language Identification', and in many other libraries. Because of Ruby's 'monkey patching', it's pretty easy to add - you just recursively browse the ancestors. Alas, because attributes are stored internally as strings and not an Attribute object, there does not seem to be any way of monkey patching §2.12 support on to REXML's attribute handling.

One day, Ruby will have a really good XML parser - speedy as a SAX and fully DOMinanting over the vagaries of namespaces etc.

Enclosed is an RSpec test that demonstrates usage.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.