diff --git a/mephi.xml b/mephi.xml new file mode 100644 index 0000000..779af5e --- /dev/null +++ b/mephi.xml @@ -0,0 +1,22 @@ + + + + + + Anisimova Natalia + Artemiev Dmitriy + Bubenko Kirill + Jelouhova Alena + Zamanov Aynur + Miheev Denis + Pivovarov Sasha + Samsonov Artem + Solovieva Anna + Sidorova Liubov + Tarmazakov Evgeniy + Titorenko Alexey + Shtaniko Sasha + + + + diff --git a/programm_typing.py b/programm_typing.py new file mode 100755 index 0000000..4411976 --- /dev/null +++ b/programm_typing.py @@ -0,0 +1,20 @@ +#! /usr/bin/env python +import sys, libxml2 + +def open(mephi_xml): + doc = libxml2.parseFile(mephi_xml) + doc.freeDoc() + +def main(argv): + open(argv[1]) + from xml.dom.minidom import * + + xml = parse('mephi.xml') + name = xml.getElementsByTagName('student') + +for node in name: + print node.childNodes[0].nodeValue + + +if __name__ == '__main__': + main(sys.argv) diff --git a/validate_xml.py b/validate_xml.py new file mode 100644 index 0000000..885f1d0 --- /dev/null +++ b/validate_xml.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +#-*- coding: UTF-8 -*- + +import optparse, libxml2 + +def validate(xml_file, dtd_file): + doc = libxml2.parseFile(xml_file) + dtd = libxml2.parseDTD(None, dtd_file) + ctxt = libxml2.newValidCtxt() + ret = doc.validateDtd(ctxt, dtd) + dtd.freeDtd() + doc.freeDoc() + return ret + +def main(): + op = optparse.OptionParser(description = U"Проверка на соответствие DTD", prog="dtd",version="0.1",usage=U"%prog") + op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE") + op.add_option("-d", "--dtd", dest="dtd", help=U"DTD document", metavar="DTD_FILE") + options, arguments = op.parse_args() + if options.xml and options.dtd: + validate(options.xml, options.dtd) + else: + op.print_help() + +if __name__ == '__main__': + main() diff --git a/xpath.py b/xpath.py new file mode 100644 index 0000000..0dbb67c --- /dev/null +++ b/xpath.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +import sys, libxml2 + +def open(xml_file, query): + doc = libxml2.parseFile (xml_file) + ctxt = doc.xpathNewContext() + students = ctxt.xpathEval(query) + print students + ctxt.xpathFreeContext() + doc.freeDoc() + +def main(argv): + queries = ["string(/university/faculty[@name='K']/*/attribute::name)", + "//group[@entryyear>='2012']/*", + "string(//group[child::student='Sidorova Liubov']/attribute::name)", + "count(//group[@name='361'][@entryyear='2012']/*)", + "count(//department[@name='Information tehnology']/descendant::student)", + "string(//faculty[child::department[@name='361']]/attribute::name)", + "concat(string(//faculty/attribute::name),string(1+2*(2014.0-number(//group/attribute::entryyear))),'-',string(//group/attribute::name))"] + for s in queries: + print s + print + open(argv[1], s) + print + +if __name__ == '__main__': + main(sys.argv)