A
A
Alexey2015-12-14 03:28:45
Django
Alexey, 2015-12-14 03:28:45

How to work with XML data in Django?

Hello, I am writing a Django application. The application sends an XML request and receives an XML response, which looks something like this:

<Root>
   <Header>Header data</Header>
   <Main>
      <Product>
         <Name>Name1</Name>
         <Description>Description1</Description>
      </Product>
      <Product>
         <Name>Name2</Name>
         <Description>Description1</Description>
      </Product>
   </Main>
</Root>

I want to first display this data in a template as a table, and then make it possible for the user to select one of these products.
Please tell me the best way to implement this. I was thinking about converting this data to a dictionary and attaching an identifier to it, but I'm not sure if my thoughts are correct. That's why I'm asking for your help, thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nirvimel, 2015-12-14
@nirvimel

  1. Parse with lxml .
  2. Convert to dictionary. For example, officially recommended , method or other .
  3. At this step, it would be nice to validate the data to form intelligible error messages in the server responses, but at the prototyping stage, you don’t have to worry about it.
  4. Access the resulting structure from the template in the most common way, as you would access the structure selected from the database.

V
Vladimir, 2015-12-14
@vintello

1. You need to communicate with XML at the server-server level.
2. Having received the data, put it in a table and pass it to the user in the usual form in the browser.
3. put the results of form processing into django, post-process the data, and then transfer it to another server.
with this scheme of work, you will always know what came in, what the user added or changed, and what went to another server.
You need to study well serialization and desirilization of objects well and then decide how to do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question