From e5a97efef86a9f85db5934310536c78f4ca21c33 Mon Sep 17 00:00:00 2001 From: C-o-m-o-n Date: Sat, 30 Dec 2023 15:56:15 +0300 Subject: [PATCH] add xml to json --- docs/index.html | 26 ++++++++++++++++++ examples.py | 11 ++++++-- .../__pycache__/pytextbin.cpython-311.pyc | Bin 16089 -> 16083 bytes pytextbin/pytextbin.py | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 9f15352..264194e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -123,6 +123,32 @@

Convert JSON and CSV

#id,name #12,Collins + + + + +

Convert JSON and xml

+
+
+        
+        from textbin.textbin import *
+        textbin_obj = textbin.Textbin()
+
+        #convert json to xml
+        json_data = { 'id' : 12 , 'name' : 'Collins' }
+        converted = textbin_obj.json_to_xml(json_data)
+        print(converted)
+
+        #Output 12Collins
+
+        #convert xml to  json
+        xml_data = "12Collins"
+        converted = textbin_obj.xml_to_json(xml_data)
+        print(converted)
+        print(converted)
+
+        #Output { 'id' : 12 , 'name' : 'Collins' }
+      
       
     
diff --git a/examples.py b/examples.py index 1d1e7b2..a3d5cbd 100644 --- a/examples.py +++ b/examples.py @@ -55,9 +55,16 @@ #convert json to xml print("convert json to xml") -json_list = [{ 'id' : 12 , 'name' : 'Collins' }] -converted = textbin_obj.json_to_xml(json_list) +json_data = { 'id' : 12 , 'name' : 'Collins' } +converted = textbin_obj.json_to_xml(json_data) print(converted) print("************************************************************\n") +#convert xml to json +print("convert xml to json") +xml_data = "12Collins" +converted = textbin_obj.xml_to_json(xml_data) +print(converted) + +print("************************************************************\n") diff --git a/pytextbin/__pycache__/pytextbin.cpython-311.pyc b/pytextbin/__pycache__/pytextbin.cpython-311.pyc index 9fd1a0cb29d320b80032c7743c8eaab6b902af8c..8e26e4e1d45e4acf8119300d146862581f6a1e34 100644 GIT binary patch delta 100 zcmcavd%2c(IWI340}z-oOh`Srk@uNC*8)ZchUpA7j76s>|J8Sz?5iQP+25dzk+sMV zsBH2h!}&bZt0z@2Fuy3SeMMY*bFYyp8)Mhx!xsLGJ)4Cs?=my?P5x+8!8m_&mTf*G E0H6gT^#A|> delta 108 zcmV-y0F(dIec62trwt7X00000fxL-j!m$nJFAAOk005T&d;xOGll?D3lRpj+vr#aH z0S(# Union[dict, list]: if element: if element.attrib: return {element.tag: element.attrib} - children = element.getchildren() + children = element.get(self) if children: out = {} for child in children: