Article Sabit Issakhan · Jun 8, 2020 1m read

Convert XML to JSON

Hello everyone! 

I have had problem with XML format in Cache Object Script, it was diffucult to parse XML format,

So i decided to convert XML to JSON and parse json easily

So for that i wrote code in java which convert xml to json and build package with maven

Anyone interested can download jar file and see the instructions at the link:

https://github.com/Sabit2092/xmlToJsonCache
 

Comments

Eduard Lebedyuk · Jun 8, 2020

Interesting.

Can you please add source code for java classes, such as ParseXML.Parse?

0
Sabit Issakhan  Jun 9, 2020 to Eduard Lebedyuk

Sure.

Class ParseXML.Parse Extends java.lang.Object [ ProcedureBlock ]
{

Method %OnNew(ByRef p0 As %ObjectHandle) As %Status
{
Quit:'$D(p0) $$$OK
Quit ..%Constructor(p0,"ParseXML.Parse",0)
}Method convertXMLtoJSON(ByRef p0 As %ObjectHandle) As %ObjectHandle
{
Quit ..%IR("convertXMLtoJSON",.p0)
}}

0
Evgeny Shvarov · Jun 9, 2020

Hi Sabit!

Looks interesting!

But I see only jar files in the repo. Could you please submit java source files too?

0
Rubén Larenas · Jan 9, 2023

Using Embedded Python is quite more simple

Method XML2JSON(iXml As %String) [ Language = python ]
{
	import xmltodict, json
    
	#; print(iXml)
	obj = xmltodict.parse(iXml)
	return(json.dumps(obj))
}

Just need install 

.\irispip.exe install xmltodict

0