quandyfactory / dicttoxml

Simple library to convert a Python dictionary or other native data type into a valid XML string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creates invalid XML when a dict has keys containing "/"

gdude2002 opened this issue · comments

Let's say I have this JSON..

{
    "routes": {
        "/test/[test variable]": {
            "GET": "A test route"
        },
        "/routes": {
            "GET": "The list of routes in a computer-readable format"
        }
    }
}

This gives us..

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <routes type="dict">
        </test/[test variable] type="dict">
            <GET type="str">A test route</GET>
        <//test/[test variable]>
        </routes type="dict">
            <GET type="str">The list of routes in a computer-readable format</GET>
        <//routes>
    </routes>
</root>

This is invalid XML. Any ideas?

Good catch - thanks for bringing this to my attention. I'll have to update the code so it escapes slashes in key names.

That'd be awesome of you, thanks. We're kind of stuck without this working, heh.

I'll try to fix it this afternoon.

<3

On Fri, Aug 15, 2014 at 7:41 PM, Ryan McGreal notifications@github.com
wrote:

I'll try to fix it this afternoon.


Reply to this email directly or view it on GitHub
#24 (comment)
.

Any luck on this, or is it simple enough that I can make a PR?

Sorry, I haven't had a chance to tackle this yet. I hope to have some time later today but will try to update you either way.

So I've had a chance to look at this and we have the following issue: XML element names can not contain special characters, even if they are escaped. The best we could do is to call the key "key" and put the name of the route in a "name" attribute. If we implement this, your XML output would look like the following:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <routes type="dict">
        <key name="/test/[test variable]" type="dict">
            <GET type="str">A test route</GET>
        </key>
        <key name="/routes" type="dict">
            <GET type="str">The list of routes in a computer-readable format</GET>
        </key>
    </routes>
</root>

Does this meet your needs?

That's absolutely fine (and basically what I was expecting). Would be
awesome if we could do this. :3

On Mon, Aug 18, 2014 at 9:26 PM, Ryan McGreal notifications@github.com
wrote:

So I've had a chance to look at this and we have the following issue: XML
element names can not contain special characters, even if they are escaped.
The best we could do is to call the key "key" and put the name of the route
in a "name" attribute. If we implement this, your XML output would look
like the following:

A test route The list of routes in a computer-readable format

Does this meet your needs?


Reply to this email directly or view it on GitHub
#24 (comment)
.

Issue should be fixed in v. 1.5.6. Thanks for bringing this issue to my attention.