New question #233331 on Sikuli:
https://answers.launchpad.net/sikuli/+question/233331

Hello there,

I've been trying to parse an xml file and write selected nodes to a text file. 
If I run the script from within Sikuli IDE, everything works fine. The run 
produces expected xmltest.txt file into the current directory.
The problem arises when I run the same script from command line., it throws No 
parsers found error.

I run it as,
D:\INSTALLER\sikuli-script.cmd -r D:\test.sikuli

The error is,
+++ trying to start Sikuli Script
[error] Script aborted with some error:
Traceback (most recent call last):
  File "D:\test.py", line 22, in <module>
    t1 = parse_xml(file_name)
  File "D:\test.py", line 15, in parse_xml
    dom = read_xml(file_name)
  File "D:\test.py", line 10, in read_xml
    pdata = parseString(data)
  File "D:\INSTALLER\sikuli-script.jar\Lib\xml\dom\minidom.py", line 1934, in 
parseString
  File "D:\INSTALLER\sikuli-script.jar\Lib\xml\dom\minidom.py", line 1907, in 
_do_pulldom_parse
  File "D:\INSTALLER\sikuli-script.jar\Lib\xml\dom\pulldom.py", line 351, in 
parseString
  File "D:\INSTALLER\sikuli-script.jar\Lib\xml\sax\__init__.py", line 94, in 
make_parser
xml.sax._exceptions.SAXReaderNotAvailable: No parsers found


Sikuli Script:
-------------
import os
from xml.dom.minidom import parseString
cd = os.path.dirname(os.path.abspath(sys.argv[0]))
file_name = cd+"\\test.xml"

# read xml
def read_xml(xml_file):
    f = open(xml_file, 'r')
    data = f.read()
    pdata = parseString(data)
    f.close()
    return pdata

def parse_xml(file_name):
    dom = read_xml(file_name)
    node_list = dom.getElementsByTagName('node')
    first_node = node_list[0].firstChild.nodeValue
    return first_node

fo = open(cd+'\\xmltest.txt', 'a')
fo.write("\nFirst node value\n")
t1 = parse_xml(file_name)
fo.write(str(t1))
fo.close()

XML file:
----------
<?xml version="1.0"?>
<test>
        <tag1>
                <node>VALUE</node>
        </tag1>
</test>


Output xmltest.txt file, if run through Sikuli IDE,
-----------------
First node value
VALUE

Occasionally, the IDE also throws same parser not found error that can be rid 
of by clearing all sikuli temp data.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.

_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help   : https://help.launchpad.net/ListHelp

Reply via email to