quandyfactory/dicttoxml

Is there a way to not include the item tag in a list?

Opened this issue ยท 10 comments

Is there a way to not include the item tag in a list?

The latest version includes the ability to customize the name of the item elements. Does this change meet your requirements?

@Euphorbium can you create a PR for your fix? I'm sure it is a welcome feature :)
I just used your fork and it worked fine :)

@patrick91 pull request #44 opened on Nov 8, 2015

Oh, sorry I thought I checked! Hope @quandyfactory will merge that soon then :)

What i don't want tag in my XML? It is always there...i can change its name but i cannot remove this. is there any way to remove it?

@arslanqadeer what I did was to add a None tag, convert the XML to string, replace the None tag with empty string. Here is how I did:

dicttoxml.dicttoxml(....., item_func=lambda x: None).replace('<None>', '').replace('</None>', '')

This solved my problem but I am sure this needs to be inbuilt.

@vaddipar works fine, thank you ๐Ÿ‘ but we need to convert the output to string object

result = dicttoxml.dicttoxml(....., item_func=lambda x: None)
result = str(result).replace('<None>', '').replace('</None>', '')

any updates here in almost 2022?)

@akarev0 : I encountered the same problem. My intermediate solution is to convert the object to string and do a replace:

xml_str = str(dicttoxml.dicttoxml(json_object, attr_type=False, custom_root="MYROOT")).replace("<item>", "").replace("</item>", "")

(similar to solution that ssvaddiparthy mentioned)

@DreamZeppelin thanks, used the same approach, but it should be in library core I guess