summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric2020-02-05 10:41:22 +0530
committerEric2020-02-05 10:41:22 +0530
commit7b8bcbf94269e69d5aab2209a4e72b66eee4ca2e (patch)
tree8e3ec7863f7ac351fc945c0eb1cf0ccb6b29dae4
parent5db421c70cb0ec9055f41b5a91478676f413efd0 (diff)
downloadxcos_converter-7b8bcbf94269e69d5aab2209a4e72b66eee4ca2e.tar.gz
xcos_converter-7b8bcbf94269e69d5aab2209a4e72b66eee4ca2e.tar.bz2
xcos_converter-7b8bcbf94269e69d5aab2209a4e72b66eee4ca2e.zip
All the basic codes added
-rw-r--r--example.xml23
-rw-r--r--new.xml22
-rw-r--r--parser.py20
-rw-r--r--tree.py10
4 files changed, 75 insertions, 0 deletions
diff --git a/example.xml b/example.xml
new file mode 100644
index 0000000..e05f3c5
--- /dev/null
+++ b/example.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<data>
+ <country name="Liechtenstein">
+ <rank>1</rank>
+ <year>2008</year>
+ <gdppc>141100</gdppc>
+ <neighbor name="Austria" direction="E"/>
+ <neighbor name="Switzerland" direction="W"/>
+ </country>
+ <country name="Singapore">
+ <rank>4</rank>
+ <year>2011</year>
+ <gdppc>59900</gdppc>
+ <neighbor name="Malaysia" direction="N"/>
+ </country>
+ <country name="Panama">
+ <rank>68</rank>
+ <year>2011</year>
+ <gdppc>13600</gdppc>
+ <neighbor name="Costa Rica" direction="W"/>
+ <neighbor name="Colombia" direction="E"/>
+ </country>
+</data> \ No newline at end of file
diff --git a/new.xml b/new.xml
new file mode 100644
index 0000000..bb41392
--- /dev/null
+++ b/new.xml
@@ -0,0 +1,22 @@
+<data>
+ <country name="Liechtenstein">
+ <rank updated="yes">3</rank>
+ <year>1/1/2011</year>
+ <gdppc>141100</gdppc>
+ <neighbor direction="E" name="Austria" />
+ <neighbor direction="W" name="Switzerland" />
+ </country>
+ <country name="Singapore">
+ <rank updated="yes">6</rank>
+ <year>2011</year>
+ <gdppc>59900</gdppc>
+ <neighbor direction="N" name="Malaysia" />
+ </country>
+ <country name="Panama">
+ <rank updated="yes">70</rank>
+ <year>2011</year>
+ <gdppc>13600</gdppc>
+ <neighbor direction="W" name="Costa Rica" />
+ <neighbor direction="E" name="Colombia" />
+ </country>
+</data> \ No newline at end of file
diff --git a/parser.py b/parser.py
new file mode 100644
index 0000000..361abe5
--- /dev/null
+++ b/parser.py
@@ -0,0 +1,20 @@
+import xml.etree.ElementTree as ET
+
+xmlTree = ET.parse('/home/eric/Documents/example.xml')
+xmlRootTag = {elem.tag for elem in xmlTree.iter()}
+
+
+#xmlTree = ET.parse('/home/fossee/Documents/example.xml')
+#xmlRootTag = list({elem.tag for elem in xmlTree.iter()})
+
+#for xmlChild in xmlRootTag:
+ #if xmlChild :
+ # print(xmlChild)
+
+for xmlChild in xmlRootTag:
+ if xmlChild == 'to':
+ xmlChild = 'food'
+ #print(xmlChild)
+ #else:
+ #print(xmlChild)
+xmlTree.write('/home/eric/Documents/new.xml') \ No newline at end of file
diff --git a/tree.py b/tree.py
new file mode 100644
index 0000000..efac907
--- /dev/null
+++ b/tree.py
@@ -0,0 +1,10 @@
+import xml.etree.ElementTree as ET
+tree = ET.parse('/home/eric/Documents/example.xml')
+root = tree.getroot()
+for rank in root.iter('rank'):
+ new_rank=int(rank.text) + 2
+ rank.text = str(new_rank)
+ rank.set('updated','yes')
+tree.find('.//year').text = '1/1/2011'
+
+tree.write('/home/eric/Documents/new.xml') \ No newline at end of file