Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17360

How to convert xml to json where xml and json namings don't match

$
0
0

I have an use case where user types some message along with xml something like below and this needs to be converted to json with some generated message.Ex : User gives an xml along with some text input like below.

Can you populate populate values from my xml input

<Company trade-name="SpaceX" type="Private" xmlns:pd="http://www.company.com/prod"><Founder name="Elon" surname="Musk"/><Founded>2002-03-14</Founded><Employees>12000</Employees><WebSite>https://www.spacex.com</WebSite><Industries><Industry>space</Industry><Industry>communications</Industry></Industries><key-people><person position="CEO" name="Elon Musk"/><person position="CTO" name="Elon Musk"/><person position="COO" name="Gwynne Shotwell"/></key-people><hq:headquarters xmlns:hq="http://www.company.com/hq"><hq:country>US</hq:country><hq:state>California</hq:state><hq:city>Hawthorne</hq:city></hq:headquarters><co:contacts xmlns:co="http://www.company.com/contact"><co:socials><co:social co:type="linkedin">https://www.linkedin.com/company/spacex</co:social><co:social co:type="twitter">https://twitter.com/spacex</co:social><co:social co:type="youtube">https://www.youtube.com/spacex</co:social></co:socials></co:contacts><pd:product pd:status="running" pd:launched="2013">Several launch vehicles</pd:product><pd:product pd:status="running" pd:launched="2019">Starlink</pd:product><pd:product pd:status="development">Starship</pd:product></Company>

Output should be something like this with any AI generated message something like belowHello here is your response with values mapped.

 {"Company": {"Founder": "","Founded": "2002-03-14","Employees": 12000,"WebSite": "https://www.spacex.com","Industries": {"Industry": ["space","communications"          ]        },"headquarters": {"country": "US","state": "California","city": "Hawthorne"        },"contacts": {"socials": {"social": ["https://www.linkedin.com/company/spacex","https://twitter.com/spacex","https://www.youtube.com/spacex"            ]          }        },"product": ["Several launch vehicles","Starlink","Starship"        ]      }    }

I am thinking of to retrieve only xml from the input message and convert it to json. Can this be achieved through LLMs Any suggestions or thoughts on how to achieve this would be of great help. Can a model be trained in such a way that it gives only xml from the inputNote: XML and Json elements need not be of same name. Ex: Company in xml is mapped to Organization in json. Also XML root tag need not start with it can be or any other tag.


Viewing all articles
Browse latest Browse all 17360

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>