1

我正在尝试解析文本文件并将其转换为 xml 文件。
为此,我得到了一个代码(python3),它在我的 Windows 机器上成功执行。
但是,当我想在我的 AS400 机器上使用 jython 执行它的抛出错误时,相同的代码:

Traceback (innermost last):        
  File "<string>", line 2, in ?    
ImportError: No module named etree

这是在 windows 上为我工作的 python 脚本。

请帮助我如何解决这个问题。

Python代码:

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

我正在阅读的文本文件作为输入:

------------------------------------- 检查 websphere 应用程序状态 --------- ----------------------------- WASX7209I:使用 SOAP 连接器连接到节点 SRVR_SRVR 上的进程“SERVER1”;进程类型为:UnManagedProcess
+----------------+

状态:已停止
+--------- -------------------+
+----------------------------+
CtxRootForWebMod:指定web模块的上下文根

为 Web 模块中的上下文根配置值。
Web 模块:SessionTest.war
URI:SessionTest.war,WEB-INF/web.xml
上下文根目录:/aaa
状态:正在运行
+------------------------ ------+
+----------------+
CtxRootForWebMod: 指定web模块的上下文根

为 Web 模块中的上下文根配置值。

Web 模块:WebApp
URI:MainApp_934v123_20150605.war,WEB-INF/web.xml
上下文根目录:/mainapp_icilif
状态:已停止
+------------------------ ----+
+----------------+

输出:

<?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>
4

0 回答 0