Beispiel #1
0
def validateManifest():
    parser = xmlval.XMLValidator()
    parser.set_error_handler(utils.ErrorPrinter(parser))
    dtd = xmldtd.load_dtd('/mvista/arch/manifest.dtd')
    parser.val.dtd = parser.dtd = parser.ent = dtd
    parser.parse_resource('manifest.xml')
    return
Beispiel #2
0
 def check_dom_against_dtd(self, dom):
     """
     Check DOM again DTD.
     Doesn't give as nice error messages.
     (no location info)
     """
     dtd = xmldtd.load_dtd(self.dtd)
     app = xmlval.ValidatingApp(dtd, self)
     app.set_locator(self)
     self.dom2sax(dom, app)
Beispiel #3
0
 def check_dom_against_dtd(self, dom):
     """
     Check DOM again DTD.
     Doesn't give as nice error messages.
     (no location info)
     """
     dtd = xmldtd.load_dtd(self.dtd)
     app = xmlval.ValidatingApp(dtd, self)
     app.set_locator(self)
     self.dom2sax(dom, app)
Beispiel #4
0
def validate(file):
    print "validating..."
    d = xmldtd.load_dtd(sys.path[0] + "/xmlfapi.dtd")
    p = xmlval.XMLValidator()
    p.set_application(XmlFapiValidator())
    try:
        p.parse_resource(file)
    except:
        sys.stderr.write("Cannot validate XML source\n")
        pass
    pass
Beispiel #5
0
def validate(file):
    print "validating..."
    d = xmldtd.load_dtd(sys.path[0] + "/xmlfapi.dtd")
    p = xmlval.XMLValidator()
    p.set_application(XmlFapiValidator())
    try:
        p.parse_resource(file)
    except:
        sys.stderr.write("Cannot validate XML source\n")
        pass
    pass
Beispiel #6
0
def validate_xml(xml_filename, dtd_filename):
    """Validate a given XML file with a given external DTD.
      If the XML file is not valid, an exception will be 
      printed with an error message.
   """
    dtd = xmldtd.load_dtd(dtd_filename)
    parser = xmlproc.XMLProcessor()
    parser.set_application(xmlval.ValidatingApp(dtd, parser))
    parser.dtd = dtd
    parser.ent = dtd
    parser.parse_resource(xml_filename)
Beispiel #7
0
 def check_dtd(self, file):
     """
     Check file against DTD.
     Use this if possible as it gives nice
     error messages
     """
     dtd = xmldtd.load_dtd(self.dtd)
     parser = xmlproc.XMLProcessor()
     parser.set_application(xmlval.ValidatingApp(dtd, parser))
     parser.dtd = dtd
     parser.ent = dtd
     parser.parse_resource(file)
Beispiel #8
0
 def check_dtd(self, file):
     """
     Check file against DTD.
     Use this if possible as it gives nice
     error messages
     """
     dtd = xmldtd.load_dtd(self.dtd)
     parser = xmlproc.XMLProcessor()
     parser.set_application(xmlval.ValidatingApp(dtd, parser))
     parser.dtd = dtd
     parser.ent = dtd
     parser.parse_resource(file)
Beispiel #9
0
def validate_xml_file(xml_filename, app=None, dtd_filename=None):
    # build validating parser object with appropriate error handler
    parser = xmlval.Validator()
    parser.set_error_handler(utils.ErrorPrinter(parser))
    if dtd_filename is not None:
        # DTD file specified, load and set it as the DTD to use
        dtd = xmldtd.load_dtd(dtd_filename)
        parser.val.dtd = parser.dtd = parser.ent = dtd
    if app is not None:
        # Application processing requested, set appliation object
        parser.set_application(app)
    # everything being set correctly, finally perform the parsing
    parser.parse_resource(xml_filename)
Beispiel #10
0
def processDTD(aDTD, outFile=None):

    print("# Loading DTD %s ... to %s" % (aDTD, outFile))
    print()

    dtd = xmldtd.load_dtd(aDTD)

    c = CodeGeneratorBackend()
    c.begin()

    c.writeln("from EaseXML3 import *")
    c.writeln('')

    elements = []
    for elemname in dtd.get_elements():
        elem = dtd.get_elem(elemname)
        elements.append(Element2XO(dtd, c, elem))

    if outFile == "stdout":
        print(c.end())
    else:
        c.generate(outFile)
from xml.parsers.xmlproc import xmlproc
from xml.parsers.xmlproc import xmlval
from xml.parsers.xmlproc import xmldtd
from xml.dom.minidom import parse
from XMLUtils import childrenOf, firstChildOf

from parameters_model import ParameterSystem, Description, Text, EnumValue, Descriptions, Parameter, ParameterSystemReference, EnumeratedType, EditInfo

# XML file and corresponding DTD definition
file = '../tests/policy_parameters_for_outputs.xml'
dtd  = '../dtds/parameters2.dtd'

print 'Start XML Parsing (With DTD)'
d = xmldtd.load_dtd(dtd)
p = xmlval.XMLValidator()
## p.set_application(MyApp())
xml = p.parse_resource(file)
print p
print 'End XML Parsing (With DTD)'

desc = Description()
print desc

text = Text() 
print text

enumv = EnumValue()  
print enumv

descs = Descriptions()
print descs
Beispiel #12
0

# XML file and corresponding DTD definition
file = 'test.xml'
dtd = 'test.dtd'

# standard XML parsing, without validation against DTD
print 'Start XML Parsing (No DTD)'
p = xmlproc.XMLProcessor()
p.set_application(MyApp())
p.parse_resource(file)
print 'End XML Parsing (No DTD)'
print

# XML parsing, with validation against external DTD
# Since you are referencing an external DTD from
# test.xml, you'll need markers like:
#
#  <?xml version="1.0"?>
#  <!DOCTYPE base SYSTEM "test.dtd">
#
# (where 'base' is the root element of the XML doc)
# at the top of your XML doc

print 'Start XML Parsing (With DTD)'
d = xmldtd.load_dtd(dtd)
p = xmlval.XMLValidator()
p.set_application(MyApp())
p.parse_resource(file)
print 'End XML Parsing (With DTD)'
Beispiel #13
0
infile = sys.argv[1]
if len(sys.argv) == 3:
    outfile = sys.argv[2]
else:
    ext = os.path.splitext(infile)[1]
    outfile = os.path.split(infile)[1]
    outfile = outfile[ : -len(ext)] + ".xsd"

# --- Doing the job

print "\ndtd2schema.py\n"

# Load DTD

print "Loading DTD..."
dtd = xmldtd.load_dtd(infile)

# Find attribute groups

print "Doing reverse-engineering..."
attrinfo = find_attr_groups(dtd)

# Write out schema

print "Writing out schema"
out = open(outfile, "w")

out.write('<?xml version="1.0"?>\n')
out.write('<!--\n')
out.write('  Converted from a DTD by dtd2schema.py, using xmlproc.\n')
out.write('  NOTE: This version is not reliable. It has not been\n')
Beispiel #14
0
infile = sys.argv[1]
if len(sys.argv) == 3:
    outfile = sys.argv[2]
else:
    ext = os.path.splitext(infile)[1]
    outfile = os.path.split(infile)[1]
    outfile = outfile[:-len(ext)] + ".xsd"

# --- Doing the job

print "\ndtd2schema.py\n"

# Load DTD

print "Loading DTD..."
dtd = xmldtd.load_dtd(infile)

# Find attribute groups

print "Doing reverse-engineering..."
attrinfo = find_attr_groups(dtd)

# Write out schema

print "Writing out schema"
out = open(outfile, "w")

out.write('<?xml version="1.0"?>\n')
out.write('<!--\n')
out.write('  Converted from a DTD by dtd2schema.py, using xmlproc.\n')
out.write('  NOTE: This version is not reliable. It has not been\n')