whoisearth
whoisearth

Reputation: 4170

django rest framework - XML formatting

Can someone explain why the format of the XML looks great in the browser -

<job id="blah" name="string2" master="string3" dbversion="string4" xmlversion="string5">
    <jobmst>
        <jobmst_id>10081</jobmst_id>
        <jobmst_type>2</jobmst_type>
        <jobmst_prntid>blah blah</jobmst_prntid>
        <jobmst_active>Y</jobmst_active>
        .......

But when I save the output, or do a CURL of the page it comes out as unformatted?

<job id="blah" name="string2" master="string3" dbversion="string4" xmlversion="string5"><jobmst><jobmst_id>10081</jobmst_id><jobmst_type>2</jobmst_type><jobmst_prntid>blah blah</jobmst_prntid><jobmst_active>Y</jobmst_active>

edit - I'm learning something here. Django is formatting it to XML in the browser (good) but the source is unformatted so I need to have a separate download feature to actually format it for download?

Upvotes: 3

Views: 2046

Answers (1)

flup
flup

Reputation: 27104

It's perfectly fine for the XML that is served to be unformatted. This saves some bandwidth.

The browser is formatting the XML for you when it displays it. And most editors will allow you to format XML when you've opened it for viewing.

In linux/unix, you can also format XML on the command line after fetching it with curl.

I don't think that Django REST Framework allows you to pretty print XML out of the box. The JSON renderer has an indent option, but I cannot find one for XML. You could, if need be, write a custom pretty-printing XML renderer but I'd go for one of the above options instead.

Upvotes: 2

Related Questions