Need Help with XML pasring
#1
using the pc emulator (not tested on xbmc yet).

error:
Quote:q:\homecontrol>setcoordinateresolution= 6
setcoordinateresolution= 6
traceback (most recent call last):
 file "homecontrol.py", line 425, in ?
   mydisplay = homeseerclass()
 file "homecontrol.py", line 159, in
   self.readconfig(hs_statusfile)
 file "homecontrol.py", line 167, in readconfig
   self.dom = parsestring(open(file,'r').read())
 file "c:\python23\lib\xml\dom\minidom.py", line 1929, in parsestring
   return expatbuilder.parsestring(string)
 file "c:\python23\lib\xml\dom\expatbuilder.py", line 940, in parsestring
   return builder.parsestring(string)
 file "c:\python23\lib\xml\dom\expatbuilder.py", line 223, in parsestring
   parser.parse(string, true)
xml.parsers.expat.expaterror: syntax error: line 1, column 0

xml:
Quote:<?xml version="1.0" ?>

<homecontrol>



<!-- homeseer server name or ip address                              !-->

<!-- homeseer web server port - default is 80 unless you changed it  !-->


<hs_server server="192.168.1.11" port="81"/>


<!-- event group you want to display in xbmc, from homeseer !-->

<hs_eventgroup group="scene" />


<!-- event devices you created in homeseer for scene pairs !-->

<hs_eventdevice group="scene" />



<!-- device types from homeseer you want to exclude !-->

<hs_excludes>


<device type="virtual" />

<device type="motion sensor dd" />

</hs_excludes>





</homecontrol>

python code:
Quote:    def readconfig(self, file):
       if not os.path.exists(file):
           open(file,'w').write(create_base_config())
       self.dom = parsestring(open(file,'r').read())
       set = self.dom.documentelement.getelementsbytagname('homecontrol')[0]
       self.dir = str(set.getattribute('path'))
       hs_server = self.dom.documentelement.getelementsbytagname('hs_server')
       if hs_server:
           s = str(hs_server.getattribute('server'))
           p = str(hs_server.getattribute('port'))
           hs_server = s+':'+p
           hs_url = 'http://'+hs_server                                        # homeseer url - for sending commands
           hs_urlstatusfile = hs_url+'//'+hs_statusfile                        # homeseer currentstatus location+filename
           if testlocal == 1: hs_urlstatusfile = cwd+hs_statusfile             # if testing on local hd, not using web server

       hs_excludes = self.dom.documentelement.getelementsbytagname('hs_excludes')[0]
       hsdev = hs_excludes.getelementsbytagname('device')
       for i in hsdev:
           a = str(hs_excludes.getattribute('type'))
           self.devtype_ex.append(a)
I'm not an expert but I play one at work.
Reply
#2
just had a quick look on my test machine and i was unable to get it going but i am getting different errors to you. what imports are you using for xml as i used minidom but i suspect you are not.
Reply
#3
could it be that you aren't closing the file after you write it? try

Quote:
if not os.path.exists(filename):
f = open(filename,'w')
f.write(create_base_config())
f.close()
f = open(filename,'r')
self.dom = parsestring(f.read())
f.close()
Reply
#4
i fixed the problems with the code getting to the parsing, now i'm working on the parsing... expect more posts here Wink



I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
Need Help with XML pasring0