From 441ab5e47b14c179ef83f52e039798877f7d6de1 Mon Sep 17 00:00:00 2001 From: student Date: Sun, 21 Sep 2014 19:41:38 +0400 Subject: [PATCH 1/4] print --- print | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 print diff --git a/print b/print new file mode 100755 index 0000000..dbb670b --- /dev/null +++ b/print @@ -0,0 +1,15 @@ +#! /usr/bin/env python +import sys, libxml2 +def open(xml_file): + doc = libxml2.parseFile(xml_file) + root = doc.getRootElement() + child = root.children + while child.next is not None : + print child.content + child =child.next +def main(argv): + if len(argv) != 2: + sys.stderr.write("Usage : %s xml_file" % (argv[0],)) + else: open(argv[1]) +if __name__ == '__main__': main(sys.argv) + From 46d38831a554000b5fd0219a80e37fe8b9ed009a Mon Sep 17 00:00:00 2001 From: student Date: Sun, 21 Sep 2014 19:58:01 +0400 Subject: [PATCH 2/4] print1 --- print | 3 +++ 1 file changed, 3 insertions(+) diff --git a/print b/print index dbb670b..cf223e7 100755 --- a/print +++ b/print @@ -4,6 +4,9 @@ def open(xml_file): doc = libxml2.parseFile(xml_file) root = doc.getRootElement() child = root.children + child = child.children + child = child.children + child = child.children while child.next is not None : print child.content child =child.next From b6155b8f990f893f5912931d0186c9743c93c67a Mon Sep 17 00:00:00 2001 From: student Date: Mon, 29 Sep 2014 20:14:59 +0400 Subject: [PATCH 3/4] commit --- mephi.dtd | 1 + mephi.xml | 19 +++++++++++++++++++ valid | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 mephi.dtd create mode 100644 mephi.xml create mode 100755 valid diff --git a/mephi.dtd b/mephi.dtd new file mode 100644 index 0000000..b19c24f --- /dev/null +++ b/mephi.dtd @@ -0,0 +1 @@ + diff --git a/mephi.xml b/mephi.xml new file mode 100644 index 0000000..7a21ce2 --- /dev/null +++ b/mephi.xml @@ -0,0 +1,19 @@ + + + + +Anisimova-Nataly +Artemev-Dmitriy +Bubenko-Kiril +Jelouhova-Alena +Zamanov-Ainur +Miheev-Denis +Pivovarov-Alexandr +Samsonov-Artem +Soloveva-Anna +Sidorova-Lubov +Tarmazakov-Evgeniy +Titorenko-Aleksey +Shtanko-Alexandr + + diff --git a/valid b/valid new file mode 100755 index 0000000..65b1a11 --- /dev/null +++ b/valid @@ -0,0 +1,23 @@ +#!/usr/bin/env python +#-*- coding: UTF-8 -*- +import optparse +import sys, 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 документ", 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() From b5edceccdf666129ff9e30bdd102b3a8b213d96e Mon Sep 17 00:00:00 2001 From: student Date: Tue, 21 Oct 2014 20:06:47 +0400 Subject: [PATCH 4/4] all done tasks --- mephi.dtd | 14 ++++++++++- mephi.xml | 34 ++++++++++++++------------- mephi.xsd | 53 +++++++++++++++++++++++++++++++++++++++++ valid1 | 28 ++++++++++++++++++++++ xpath | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 17 deletions(-) create mode 100644 mephi.xsd create mode 100755 valid1 create mode 100755 xpath diff --git a/mephi.dtd b/mephi.dtd index b19c24f..9a0ec6b 100644 --- a/mephi.dtd +++ b/mephi.dtd @@ -1 +1,13 @@ - + + + + + + + + + + + + + diff --git a/mephi.xml b/mephi.xml index 7a21ce2..a9b86a4 100644 --- a/mephi.xml +++ b/mephi.xml @@ -1,19 +1,21 @@ + - - -Anisimova-Nataly -Artemev-Dmitriy -Bubenko-Kiril -Jelouhova-Alena -Zamanov-Ainur -Miheev-Denis -Pivovarov-Alexandr -Samsonov-Artem -Soloveva-Anna -Sidorova-Lubov -Tarmazakov-Evgeniy -Titorenko-Aleksey -Shtanko-Alexandr - + +Anisimova-Nataly +Artemev-Dmitriy +Jelouhova-Kiril +Jelouhova-Alena +Zamanov-Ainur +Miheev-Denis +Pivovarov-Alexandr +Samsonov-Artem +Soloveva-Anna +Sidorova-Lubov +Tarmazakov-Evgeniy +Titorenko-Aleksey +Shtanko-Alexandr + +kj + diff --git a/mephi.xsd b/mephi.xsd new file mode 100644 index 0000000..f6717bd --- /dev/null +++ b/mephi.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/valid1 b/valid1 new file mode 100755 index 0000000..867972a --- /dev/null +++ b/valid1 @@ -0,0 +1,28 @@ +#!/usr/bin/env python +#-*- coding: UTF-8 -*- +import optparse +import sys, libxml2 +def schema_validate(xml_file, xsd_file): + ctxt = libxml2.schemaNewParserCtxt(xsd_file) + schema = ctxt.schemaParse() + validationCtxt = schema.schemaNewValidCtxt() + res = validationCtxt.schemaValidateFile(xml_file, 0) + #doc = libxml2.parseFile(xml_file) + #res = validationCtxt.schemaValidateDoc(doc) + #doc.freeDoc() + if res != 0: + print "VALIDATION FAILED" + else: + print "VALIDATED" + return res + +def main(): + op = optparse.OptionParser(description = U"Проверка на соответствие XSD", prog="xsd", version="0.1", usage=U"%prog") + op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE") + op.add_option("-s", "--xsd", dest="xsd", help=U"XSD документ", metavar="XSD_FILE") + options, arguments = op.parse_args() + if options.xml and options.xsd: + schema_validate(options.xml, options.xsd) + else: + op.print_help() +if __name__ == '__main__': main() diff --git a/xpath b/xpath new file mode 100755 index 0000000..627292f --- /dev/null +++ b/xpath @@ -0,0 +1,70 @@ +#! /usr/bin/env python +import sys, libxml2 +def open(xml_file): + doc = libxml2.parseFile (xml_file) + ctxt = doc.xpathNewContext() + # 1 + fak = ctxt.xpathEval("//fakultet[@fak='kib']/child::*") + print "1" + i=0; + for element in fak: + print fak[i].properties.content + i=i+1 + # 2 + stud = ctxt.xpathEval("//grop[@year>2010]/child::*") + print "2" + i=0; + for element in stud: + print stud[i].content + i=i+1 + # 3 & 8 + grop = ctxt.xpathEval("//student[@Name='Anisimova']/parent::*") + print "3&8" + i=0 + for element in grop: + for property in grop[i].properties: + print property + i=i+1 + # 4 + stud = ctxt.xpathEval("//grop[@year=2012 and @gr=361]/child::*") + i=0; + for element in stud: + i=i+1 + print "4" + print i + + #5 + st = ctxt.xpathEval("//kafedra[@kaf=36]/grop/child::*") + i=0; + for element in st: + i=i+1 + print "5" + print i + + #6???? + fak = ctxt.xpathEval("//fakultet[@fak=kib]/kafedra/grop/child::*") + i=0 + for element in fak: + i=i+1 + print "6" + print i + + #7 + fak = ctxt.xpathEval("//kafedra[@kaf=36]/ancestor::fakultet") + print "7" + print fak[0].properties + + ctxt.xpathFreeContext () + doc.freeDoc () + + + ctxt.xpathFreeContext () + doc.freeDoc () + + + +def main(argv): + if len(argv) != 2: + sys.stderr.write("Usage : %s xml_file" % (argv[0],)) + else: open(argv[1]) +if __name__ == '__main__': main(sys.argv)