6

How should colander be used for xml deserialization? Docs say that it can even be used for xml deserialization and validation, but I didn't find any good examples for that in docs or on the web!

If anyone has used colander for xml deserialization can you just put a snippet here on its usage? It would be very helpful.

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
Neo
  • 4,682
  • 8
  • 44
  • 64

1 Answers1

7

Look at colander as a tool for 'deserialization/validation from a python dictionary'. A dict in Python can be formed from any structured data format, I guess.

In one of my projects I validate POST (webob.multidict) data and a JSON file and use the same lines of code:

recipe_schema = RecipeSchema()
try:
    appstruct = recipe_schema.deserialize(cstruct)
...

cstruct is always a dict, as mentioned above - sometimes made of processed Multidict, sometimes made of json.load(json_data).

So, transform XML to dict first and then validate the dict with colander.

Community
  • 1
  • 1
yentsun
  • 2,369
  • 25
  • 36