Problem with xmlproc

Marco Meoni <[email protected]>
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
Hello everybody.
I have a problem with xmlproc.
If I have a dtd in the direcory of this file, the parser send me to 
video the elelments and the attirbutes of the dtd.
this is the video output:

sbaush@sbaush:/media/hda5/Universita'/Tesi/Manager$ python parser2.py
ELEMENTO: meshap-manager - (u'|', [(u'iptables-request', ''), 
(u'iptables-response', ''), (u'routing-table-request', ''), 
(u'routing-table-response', '')], '')
ELEMENTO: iptables-request - (u'|', [(u'policy', ''), (u'list', ''), 
(u'flush', ''), (u'append', ''), (u'delete', '')], '')
ELEMENTO: policy - EMPTY
ATTRIBUTO: chain - Elemento: policy - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #REQUIRED - Default:[None]
ATTRIBUTO: target - Elemento: policy - Contenuto: [u'DROP', u'ACCEPT', 
u'REJECT'] #REQUIRED - Default:[None]
ELEMENTO: list - EMPTY
ATTRIBUTO: chain - Elemento: list - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #IMPLIED - Default:[None]
ELEMENTO: flush - EMPTY
ATTRIBUTO: chain - Elemento: flush - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #IMPLIED - Default:[None]
ELEMENTO: append - (u',', [(u'protocol', u'?'), (u'source', u'?'), 
(u'destination', u'?'), (u'jump', '')], '')
ATTRIBUTO: chain - Elemento: append - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #REQUIRED - Default:[None]
ELEMENTO: protocol - EMPTY
ATTRIBUTO: type - Elemento: protocol - Contenuto: [u'tcp', u'udp', 
u'icmp'] #REQUIRED - Default:[None]
ELEMENTO: source - EMPTY
ATTRIBUTO: address - Elemento: source - Contenuto: CDATA #REQUIRED - 
Default:[None]
ELEMENTO: destination - EMPTY
ATTRIBUTO: address - Elemento: destination - Contenuto: CDATA #REQUIRED 
- Default:[None]
ELEMENTO: jump - EMPTY
ATTRIBUTO: option - Elemento: jump - Contenuto: [u'DROP', u'ACCEPT', 
u'REJECT'] #REQUIRED - Default:[None]
ELEMENTO: delete - (u'|', [(u',', [(u'protocol', u'?'), (u'source', ''), 
(u'jump', '')], ''), (u'number', '')], '')
ATTRIBUTO: chain - Elemento: delete - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #REQUIRED - Default:[None]
ELEMENTO: number - EMPTY
ATTRIBUTO: line - Elemento: number - Contenuto: CDATA #REQUIRED - 
Default:[None]
ELEMENTO: iptables-response - (u'|', [(u'done', ''), (u'listtable', 
'')], '')
ELEMENTO: done - EMPTY
ATTRIBUTO: value - Elemento: done - Contenuto: [u'true', u'false'] 
#REQUIRED - Default:[None]
ELEMENTO: listtable - ('', [(u'table', u'+')], '')
ELEMENTO: table - ('', [(u'rule', u'*')], '')
ATTRIBUTO: chain - Elemento: table - Contenuto: [u'INPUT', u'OUTPUT', 
u'FORWARD'] #REQUIRED - Default:[None]
ATTRIBUTO: policy - Elemento: table - Contenuto: [u'ACCEPT', u'DROP', 
u'REJECT'] #REQUIRED - Default:[None]
ELEMENTO: rule - EMPTY
ATTRIBUTO: number - Elemento: rule - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: target - Elemento: rule - Contenuto: [u'ACCEPT', u'DROP', 
u'REJECT'] #REQUIRED - Default:[None]
ATTRIBUTO: protocol - Elemento: rule - Contenuto: [u'tcp', u'udp', 
u'icmp'] #REQUIRED - Default:[None]
ATTRIBUTO: option - Elemento: rule - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: source - Elemento: rule - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: destination - Elemento: rule - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: description - Elemento: rule - Contenuto: CDATA #REQUIRED - 
Default:[None]
ELEMENTO: routing-table-request - EMPTY
ELEMENTO: routing-table-response - ('', [(u'route', '')], '')
ELEMENTO: route - ('', [(u'row', u'*')], '')
ELEMENTO: row - EMPTY
ATTRIBUTO: interface - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: destination - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: gateway - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: flags - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: refcnt - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: use - Elemento: row - Contenuto: CDATA #REQUIRED - Default:[None]
ATTRIBUTO: metric - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: mask - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: mtu - Elemento: row - Contenuto: CDATA #REQUIRED - Default:[None]
ATTRIBUTO: window - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]
ATTRIBUTO: irtt - Elemento: row - Contenuto: CDATA #REQUIRED - 
Default:[None]

It works perfectly. The question is: what is the "u" in the elements??
Thanks to all.
below there is my code.


from xml.parsers.xmlproc import xmlproc
import sys

class DTDReporter(xmlproc.DTDConsumer):
    "A simple class that just prints out the events it receives."

    def __init__(self,parser,out=sys.stdout):
        xmlproc.DTDConsumer.__init__(self,parser)
        self.out=out

    def new_attribute(self,elem,attr,a_type,a_decl,a_def):
        self.out.write("ATTRIBUTO: %s - Elemento: %s - Contenuto: %s %s 
- Default:[%s]\n" % (attr,elem,a_type,a_decl,a_def))

    def new_element_type(self,elem_name,elem_cont):
        self.out.write("ELEMENTO: %s - %s\n" % (elem_name,elem_cont))

    # --- Client methods

    def close(self):
        self.out.close()

# --- Main program

if __name__ == '__main__':
    t=xmlproc.DTDParser()
    t.set_dtd_consumer(DTDReporter(t))
    #Si sceglie se parsare il file messo come input da tastiera o se il 
file sul disco. Si puo' dare anche il percorso di localizzazione del file.
    #t.parse_resource(sys.argv[1])
    t.parse_resource("MeshAP2.dtd")
   


-- 

mail address: [email protected] <mailto:[email protected]>
web site: www.marcomeoni.net <http://www.marcomeoni.net/>

_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.