11 May 2005
Hankering after an XML file format
I had a task at work that required manual editing of LDIF files to repair a problem in an LDAP directory. The editing work was repetitive and error-prone and I could see no quick way to automate the changes.
For one file with 14 entries and another with 93, I had to:
- only use entries that contain ‘problem’ attributes, ignoring others
- write LDIF lines with an entry’s DN followed by
changetype: deleteand an empty line - write LDIF lines with an entry’s DN followed by
changetype: add, then all the remaining attributes, excluding the ‘problem’ ones
After that the LDIF files will be used with ldapmodify to repair the directory.
For someone versed in XML and XSLT, doing this kind of work in LDIF file format feels extremely tedious. I couldn’t help myself: I wrote a Python script that parses the LDIF and writes a simple XML file with the same information. Then I wrote an XSLT stylesheet that edits the XML as described above. The XSLT emits LDIF directly, including ‘folding’ lines (as described in the RFC) longer than 78 characters.
I discovered DSML (Directory Services Markup Language) but could not find tools to convert LDIF to DSML. There are tools that interact with a directory using DSML files but they didn’t extract the ‘problem’ attributes (they were operational attributes actually) that I needed to filter on. Also, DSML is much more complex than I needed: my simple XML was enough.
On reflection, I probably should have used Python objects (and later Java objects after I rewrote the conversion program into the standard language where I work). But I was annoyed by what feels like an archaic file format that is not amenable to automated, declarative transformation using (now standard) tools.
