RtmDtdValidator.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # @file RtmDtdValidator.py
5 # @brief XML validator based on specified DTD file
6 # @date $Date: 2005-05-12 09:06:19 $
7 # @author K.Kitagaki
8 #
9 # Copyright (C) 2004-2005
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id$
17 #
18 
19 # dtdValidator.py -- xml with DTD Validator
20 # (C)K.Kitagaki 2004.8.26
21 #
22 # # usage
23 # import dtdValidator
24 # validator = dtdValidator.DtdValidator()
25 # errors = validator.parse("filename.xml")
26 #
27 # for (filename, line, col, msg) in errors:
28 # print filename, line, col, msg
29 #
30 # -xml$B$r(BDTD$B$K4p$-8!>Z$9$k!#(B
31 
32 from _xmlplus.parsers.xmlproc import xmlval, xmlapp, errors
33 
34 # XML validator
36  def __init__(self):
37  self.parser = xmlval.XMLValidator()
39 
40  def parse(self, fileName):
41  sysid = fileName
42 # print sysid
43  self.parser.reset()
44  self.errors.reset()
45  self.parser.set_error_handler(self.errors)
46  self.parser.parse_resource(sysid)
47 
49  return self.errors.errors
50 
51 # XML ErrorHandler
52 class ErrorRecorder(xmlapp. ErrorHandler):
53  def __init__(self, locator, warnings=1):
54  xmlapp.ErrorHandler.__init__(self, locator)
55  self.show_warnings=warnings
56  self.reset()
57 
58  def warning(self,msg):
59  if self.show_warnings:
60  self.__add_error(msg)
61 
62  def error(self,msg):
63  self.__add_error(msg)
64 
65  def fatal(self,msg):
66  self.__add_error(msg)
67 
68  def reset(self):
69  self.errors=[]
70 
71  def __add_error(self,msg):
72  self.errors.append((self.locator.get_current_sysid(),
73  self.locator.get_line(),
74  self.locator.get_column(),
75  msg))
def __init__(self, locator, warnings=1)
def parse(self, fileName)
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
Definition: NVUtil.cpp:354
for (sysid, line, col, msg) in self.errors.errors: print sysid, line, col, msg


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:44