Django

Code

Ticket #3094 (reopened)

Opened 2 years ago

Last modified 2 months ago

XML validation shouldn't require Jing; should use other tools if available.

Reported by: goliath.mailinglist@gmx.de Assigned to: adrian
Milestone: Component: Validators
Version: Keywords: relaxng validator
Cc: sam@robots.org.uk Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I disliked the fact that Django calls an external program to do XML-validation. So I wrote a validation-class that uses lxml (which is a wrapper for libxml2) for validation. This class uses the error-messages found in the original class (so all messages get translated), but could support more verbose messages, as lxml tells you more details, but then the included translations would not work anymore. This class can be used as some kind of drop-in replacement. Perhaps it can be included in the official release. Drawback: You need to write RelaxNG-files, libxml2 does not support RelaxNG-Compact (AFAIK). So perhaps it's best to let the user decide which one to use.

Attachments

validators.py (3.3 kB) - added by David Danier <goliath.mailinglist@gmx.de> on 12/05/06 16:08:05.
validator.py including RelaxNG-class
validators.2.py (3.3 kB) - added by David Danier <goliath.mailinglist@gmx.de> on 12/06/06 07:37:51.
validators.py including RelaxNG-class
validators.3.py (5.4 kB) - added by David Danier <goliath.mailinglist@gmx.de> on 05/16/08 03:08:09.

Change History

12/05/06 16:08:05 changed by David Danier <goliath.mailinglist@gmx.de>

  • attachment validators.py added.

validator.py including RelaxNG-class

12/06/06 07:36:14 changed by David Danier <goliath.mailinglist@gmx.de>

If you want to try this, but only have RelaxNG-Compaxt files consider using http://www.gnosis.cx/download/relax/. Perhaps this could be put into the validator (it's python) to convert the file on the fly (with caching), but I don't need it myself.

Update follows:

  • RelaxNG-Errors got a different Errormessage
  • Deleted unneeded import (escape)

12/06/06 07:37:51 changed by David Danier <goliath.mailinglist@gmx.de>

  • attachment validators.2.py added.

validators.py including RelaxNG-class

02/10/07 04:55:59 changed by Simon G. <dev@simon.net.nz>

  • has_patch set to 1.
  • summary changed from RelaxNG validation using lxml to [patch] RelaxNG validation using lxml.
  • stage changed from Unreviewed to Design decision needed.

03/08/07 13:34:49 changed by anonymous

  • cc set to sam@robots.org.uk.

03/12/07 06:09:38 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to wontfix.

We are trying to ship a reasonably minimal set of validators in core (and to keep external dependencies down). Obviously that isn't a perfectly consistently applied policy, since some validators from the pre-history of Django's development are available. But we are trying to be more consistent these days.

However, this does look like a useful validator for some projects. I would suggest adding a new wiki page linked from CookBookValidators or a pointer to an external site on that page so that people who would like to use this can have access to it.

Thanks for writing this validator.

02/28/08 11:17:45 changed by jacob

  • status changed from closed to reopened.
  • resolution deleted.
  • summary changed from [patch] RelaxNG validation using lxml to XML validation shouldn't require Jing; should use lxml if avaialble..

The current XML validator relies on Jing, which is even *more* of a pain to install than lxml (GJC.... ugh). I think the right approach is to refactor the XML validator to use a series of backends to try validation -- lxml if available, jing if available and if you're using RNG-Compact, and finally minidom for basic well-formedness.

I'm gonna steal this ticket for that issue since this lxml validator is a good place to start.

02/28/08 11:17:51 changed by jacob

  • stage changed from Design decision needed to Accepted.

03/02/08 09:57:10 changed by jacob

Also see #5703 for a validator using RNV. I'm wondering if we might want to have some sort of "registry" for XML validation methods; there seem to be a bunch, all with their own good use cases.

03/02/08 09:58:01 changed by jacob

  • summary changed from XML validation shouldn't require Jing; should use lxml if avaialble. to XML validation shouldn't requre Jing; should use other tools if available..

05/16/08 03:08:09 changed by David Danier <goliath.mailinglist@gmx.de>

  • attachment validators.3.py added.

05/16/08 03:10:35 changed by David Danier <goliath.mailinglist@gmx.de>

  • summary changed from XML validation shouldn't requre Jing; should use other tools if available. to XML validation shouldn't require Jing; should use other tools if available..

As this ticket seems to get attention again I uploaded a current version of my validator, supporting both newforms and oldforms. As sample of an XmlField? for newforms is included, but commented out. Hope this helps getting things forward. ;-)


Add/Change #3094 (XML validation shouldn't require Jing; should use other tools if available.)




Change Properties
Action