I am trying to parse a text file and convert it to xml file.
For that i got one code(python3) which got executed successfully on my windows machine.
But, the same code when i wanted to execute on my AS400 machine with jython its throwing error:
Traceback (innermost last):
File "<string>", line 2, in ?
ImportError: No module named etree
Here is the python script that worked for me on windows .
Please help me how can i resolve this issue.
Python code:
import re
import xml.etree.ElementTree as ET
from contextlib import contextmanager
import sys
rex = re.compile(r'''(?P<title>Web\s+Name
|Context\s+Root
|Status
)
\s*:?\s*
(?P<value>.*)
''', re.VERBOSE)
root = ET.Element('root')
root.text = '\n' # newline before the celldata element
with open('WasContent.txt') as f:
celldata = ET.SubElement(root, 'celldata')
celldata.text = '\n' # newline before the collected element
celldata.tail = '\n\n' # empty line after the celldata element
for line in f:
# Empty line starts new celldata element (hack style, uggly)
if line.isspace():
celldata = ET.SubElement(root, 'celldata')
celldata.text = '\n'
celldata.tail = '\n\n'
# If the line contains the wanted data, process it.
m = rex.search(line)
if m:
# Fix some problems with the title as it will be used
# as the tag name.
title = m.group('title')
title = title.replace('&', '')
title = title.replace(' ', '')
e = ET.SubElement(celldata, title.lower())
e.text = m.group('value')
e.tail = '\n'
# Display for debugging
#ET.dump(root)
# Include the root element to the tree and write the tree
# to the file.
#tree = ET.ElementTree(root)
tree = ET.ElementTree(root)
#tree.write('cell.xml', encoding='utf-8', xml_declaration=True)
tree.write('cell.xml', encoding='utf-8', xml_declaration=Tru
Text File i am reading as input:
------------------------------------- Checking websphere application status -------------------------------------- WASX7209I: Connected to process "SERVER1" on node SRVR_SRVR using SOAP connector; The type of process is: UnManagedProcess
+----------------------------+
Status: Stopped
+----------------------------+
+----------------------------+
CtxRootForWebMod: Specify the Context root of web moduleConfigure values for context roots in web modules.
Web module: SessionTest.war
URI: SessionTest.war,WEB-INF/web.xml
Context Root: /aaa
Status: Running
+----------------------------+
+----------------------------+
CtxRootForWebMod: Specify the Context root of web moduleConfigure values for context roots in web modules.
Web module: WebApp
URI: MainApp_934v123_20150605.war,WEB-INF/web.xml
Context Root: /mainapp_icilif
Status: Stopped
+----------------------------+
+----------------------------+
output:
<?xml version='1.0' encoding='utf-8'?> <root>
<celldata> <webmodule>SessionTest.war</webmodule> <contextroot>/aaa</contextroot> <status>Running</status> </celldata>
<celldata> <webmodule>MainApp_934v123_20150605.war</webmodule> <contextroot>/mainapp_icilif</contextroot> <status>Stopped</status> </celldata>
</root>