[1.0] IDE: HTML coded text not printed correctly

Asked by Jennifer Coleman

---- fixed with 1.0.1
---------------------------------------

I'm trying to start file i/o in my program & wanted to get a simple file read and print working. But sikuli isn't reading or printing the entire file.

The file is a short xml file:

<?xml version="1.0" encoding="UTF-8"?>
<flex>
 <loginFlex flexClient="https:///vsphere-client/#" username="r" pwd="v"/>
</flex>

>>>>>>>>>>I've tried two ways of coding:

from xml.dom import minidom

xmldoc = minidom.parse("/Users/colej/Documents/loginFlex2.xml")

print xmldoc.toxml()

RESULT: ?xml version="1.0" ?>

>>>>>>>>>>>>second way
import os
myfile = open("/Users/colej/Documents/loginFlex2.xml")

text = myfile.read()
print(text)

RESULT:
?xml version="1.0" encoding="UTF-8"?>

[info] Exit code: 0

And ideas on why the ENTIRE file is not being read and printed???

Thank You!

Revision history for this message
RaiMan (raimund-hocke) said :
#1

This is a problem with the message area, since it is managed itself using HTML, but not everything that goes there is transcripted correctly.

Run from command line and I guess you will see what you want.

You might as well replace all < and > with e.g. # and you will get the output too.

I will make it a bug now finally ;-)

Revision history for this message
Jennifer Coleman (colej) said :
#2

Thanks RaiMan!!

That worked, sort of.

The first time I ran the original file i got an ImportError.

File "/Users/colej/Documents/xml.sikuli/xml.py", line 2, in <module>
    from xml.dom import minidom
ImportError: No module named dom !!WHILE IMPORTING!!

When I removed the code:
from xml.dom import minidom

xmldoc = minidom.parse("/Users/colej/Documents/loginFlex2.xml")

print xmldoc.toxml()

The entire file was returned via command line! :)

Why couldn't Sikuli find the dom module? And will the bug on the message area be fixed soon?? :)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--- from xml.dom import minidom
confirmed: there is some sort of problem with this import.
But it only happens, when a script is run (either with Sikuli or with plain Jython).
In interactive mode (Sikuli as well as Jython) it works.
So it seems to be a Jython problem, but currently I cannot tell you why.
Since I am currently busy with 1.0.1, I have no time to track this down.

You might find out, wether there is another xml module, that you can use.

--- HTML formatting problems in message area
It is on the list, but with low priority.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

for the HTML text output this is a workaround:

instead of
print x

use:
print x.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")

--- make a def or lambda to use it more often

htmlEncode = lambda x: x.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")

print htmlEncode(x)

Revision history for this message
RaiMan (raimund-hocke) said :
#5

I fixed the HTML output problem with the version 1.0.1.

You might try it already with the preview: faq 2269

Revision history for this message
RaiMan (raimund-hocke) said :
#6

I again checked the problem with
from xml.dom import minidom

I checked it with any combination of Sikuli and Jython 2.5.3 and 2.5.4:
I do not get the error.

The only situation:
if a xml.sikuli can be found in sys.path (might be in the same directory or even the current script), the import fails.
Sikuli's import support prioritizes .sikuli scripts when searching along the sys.path, so a Sikuli script should not be named as a Python module, when this Python module should be imported.

Nevertheless I leave this a s bug, to check wether this can be avoided somehow.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

is solved