From 5334eb3c62f3820ccc0251fda92308c19b371fbe Mon Sep 17 00:00:00 2001 From: Sergred Date: Tue, 9 Sep 2014 23:06:35 +0400 Subject: [PATCH 01/14] Added xml file --- xml/mephi.xml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 xml/mephi.xml diff --git a/xml/mephi.xml b/xml/mephi.xml new file mode 100644 index 0000000..ffcb403 --- /dev/null +++ b/xml/mephi.xml @@ -0,0 +1,41 @@ + + + + + + Артемьев Дмитрий + Анисимова Наталья + Бубенко Кирилл + Джелоухова Алена + Заманов Айнур + Михеев Денис + Пивоваров Александр + Самсонов Артем + Соловьева Аня + Суханова Любовь + Тармазаков Евгений + Титоренко Алексей + Штанько Александр + + + Ахметсафин Владислав + Галкин Александр + Головко Ирина + Джумайло Евгений + Ерохин Владимир + Каталкина Виктория + Левин Андрей + Молочков Ярослав + Моряшова Виктория + Полстянкин Константин + Пурик Яна + Разживин Никита + Редюк Сергей + Рябов Петр + Скок Дарья + Стрекалов Олег + Чухненко Александра + + + + From 5879fec2bdc7efc5c016591bf95c068c428896ae Mon Sep 17 00:00:00 2001 From: Sergred Date: Tue, 9 Sep 2014 23:07:14 +0400 Subject: [PATCH 02/14] Added printing script --- xml/parser.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 xml/parser.py diff --git a/xml/parser.py b/xml/parser.py new file mode 100644 index 0000000..999c1a5 --- /dev/null +++ b/xml/parser.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python +import sys, libxml2 + +def space(dep): + for i in range(0, dep): + sys.stdout.write(" ") + +depth = 0 +def view(node): + global depth + print + space(depth) + sys.stdout.write(node.name+" ") + if node.properties is not None: + for _property in node.properties: + if _property.type == "attribute": + #print _property.name + sys.stdout.write(_property.content+" ") + child = node.children + depth = depth+1 + while child.next is not None: + if child.type == "element": + view(child) + child = child.next + depth = depth-1 + sys.stdout.write(child.content) + +def open(xml_file): + doc = libxml2.parseFile(xml_file) + root = doc.getRootElement() + #print root.name + #print root.content + view(root) + 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) \ No newline at end of file From a2c0974d011ba4c3da5305362d22d1ca78ebe000 Mon Sep 17 00:00:00 2001 From: Sergred Date: Tue, 16 Sep 2014 16:19:02 +0400 Subject: [PATCH 03/14] Added dtd file --- xml/mephi.dtd | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 xml/mephi.dtd diff --git a/xml/mephi.dtd b/xml/mephi.dtd new file mode 100644 index 0000000..af7b084 --- /dev/null +++ b/xml/mephi.dtd @@ -0,0 +1,8 @@ + + + + + + + + From fab5ea2ed4ba8570cdf96014cfb20fbdd3cc91a6 Mon Sep 17 00:00:00 2001 From: Sergred Date: Tue, 16 Sep 2014 16:19:59 +0400 Subject: [PATCH 04/14] Added validating function --- xml/parser.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xml/parser.py b/xml/parser.py index 999c1a5..1c749f3 100644 --- a/xml/parser.py +++ b/xml/parser.py @@ -1,5 +1,6 @@ #! /usr/bin/env python -import sys, libxml2 +#-*- coding: UTF-8 -*- +import sys, libxml2, optparse def space(dep): for i in range(0, dep): @@ -33,10 +34,24 @@ def open(xml_file): view(root) doc.freeDoc() +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(argv): - if len(argv) != 2: - sys.stderr.write("Usage : %s xml_file" % (argv[0],)) - else: open(argv[1]) + 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: + open(options.xml) + validate(options.xml, options.dtd) + else: op.print_help() if __name__ == '__main__': main(sys.argv) \ No newline at end of file From a4b4617674058ac15366dd303eae4bec64f830ba Mon Sep 17 00:00:00 2001 From: Sergred Date: Wed, 1 Oct 2014 19:31:15 +0400 Subject: [PATCH 05/14] Added an XML Schema --- xml/mephi.xsd | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 xml/mephi.xsd diff --git a/xml/mephi.xsd b/xml/mephi.xsd new file mode 100644 index 0000000..79763a9 --- /dev/null +++ b/xml/mephi.xsd @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 18a3ae6fc48cff2a5a9b10093558d7c6d7b2df23 Mon Sep 17 00:00:00 2001 From: Sergred Date: Wed, 1 Oct 2014 19:31:53 +0400 Subject: [PATCH 06/14] Added an XML Schema validating script --- xml/xsd_parser.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 xml/xsd_parser.py diff --git a/xml/xsd_parser.py b/xml/xsd_parser.py new file mode 100644 index 0000000..b1c3dc2 --- /dev/null +++ b/xml/xsd_parser.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python +#-*- coding: UTF-8 -*- +import sys, libxml2, optparse + +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 open(xml_file): + doc = libxml2.parseFile(xml_file) + root = doc.getRootElement() + #print root.name + #print root.content + #view(root) + doc.freeDoc() + +def main(argv): + 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("--xsd", dest="xsd", help=U"XSD документ", metavar="XSD_FILE") + options, arguments = op.parse_args() + if options.xml and options.xsd: + #open(options.xml) + schema_validate(options.xml, options.xsd) + else: op.print_help() + +if __name__=='__main__': + main(sys.argv) From 1ca00c8c9d4c8c2052e9738c0739336059896405 Mon Sep 17 00:00:00 2001 From: Sergred Date: Wed, 1 Oct 2014 19:34:00 +0400 Subject: [PATCH 07/14] Modified XML file --- xml/mephi_i.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 xml/mephi_i.xml diff --git a/xml/mephi_i.xml b/xml/mephi_i.xml new file mode 100644 index 0000000..e6d1c12 --- /dev/null +++ b/xml/mephi_i.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From e1f95de1d21145cbf160bb0caa7693abbf7253e1 Mon Sep 17 00:00:00 2001 From: Sergred Date: Mon, 6 Oct 2014 19:24:56 +0400 Subject: [PATCH 08/14] Added xPath script \#6 --- xml/xpath.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 xml/xpath.py diff --git a/xml/xpath.py b/xml/xpath.py new file mode 100644 index 0000000..bdefcab --- /dev/null +++ b/xml/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(/mephi/faculty[@name='K']/*/attribute::number)", + "//group[@year>='2012']/*/attribute::*", + "string(//group[child::student[@lastname='Редюк']]/attribute::grnum)", + "count(//group[@grnum='1'][@year='2012']/*)", + "count(//department[@number='36']/descendant::student)", + "string(//faculty[child::department[@number='36']]/attribute::name)", + "concat(string(//student[@firstname='Сергей'][@lastname='Редюк']/ancestor::faculty/attribute::name), string(1+2*(2014.0-number(//student[@firstname='Сергей'][@lastname='Редюк']/ancestor::group/attribute::year))), '-', string(//student[@firstname='Сергей'][@lastname='Редюк']/ancestor::department/attribute::number), string(//student[@firstname='Сергей'][@lastname='Редюк']/ancestor::group/attribute::grnum))"] + for s in queries: + print s + print + open(argv[1], s) + print + +if __name__ == '__main__': + main(sys.argv) From 9eb728e93662f35e43c79b5903f61c4fa884965e Mon Sep 17 00:00:00 2001 From: Sergred Date: Mon, 6 Oct 2014 19:37:23 +0400 Subject: [PATCH 09/14] Modified mephi.xml --- xml/mephi_i.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/xml/mephi_i.xml b/xml/mephi_i.xml index e6d1c12..e4ae611 100644 --- a/xml/mephi_i.xml +++ b/xml/mephi_i.xml @@ -40,14 +40,4 @@ xsi:noNamespaceSchemaLocation="/home/serg/db36/xml/mephi.xsd"> - - - - - - - - - - From 87bcd59fe3b9f5d3f9d53567e7f0b6ba36beb95d Mon Sep 17 00:00:00 2001 From: Sergred Date: Sun, 12 Oct 2014 21:08:35 +0400 Subject: [PATCH 10/14] Added xslt script --- xml/xslt.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 xml/xslt.py diff --git a/xml/xslt.py b/xml/xslt.py new file mode 100644 index 0000000..9dfa7af --- /dev/null +++ b/xml/xslt.py @@ -0,0 +1,29 @@ +#! /usr/bin/env python +#-*- coding: UTF-8 -*- +import libxslt +import libxml2 +import sys +import optparse + +def transform(xml_file, xsl_file, out_file): + xml_doc = libxml2.parseFile(xml_file) + xsl_doc = libxml2.parseFile(xsl_file) + xsl = libxslt.parseStylesheetDoc(xsl_doc) + out_doc = xsl.applyStylesheet(xml_doc ,None) + xsl.saveResultToFilename(out_file, out_doc, 0) + xsl.freeStylesheet() + out_doc.freeDoc() + xml_doc.freeDoc() + +def main(argv): + op = optparse.OptionParser(description = U"XSLT преобразования", prog="xsl", version="0.1", usage=U"%prog") + op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE") + op.add_option("--xsl", dest="xsl", help=U"XSLT документ", metavar="XSL_FILE") + op.add_option("--out", dest="out", help=U"Output", metavar="OUTPUT_FILE") + options, arguments = op.parse_args() + if options.xml and options.xsl and options.out: + transform(options.xml, options.xsl, options.out) + else: op.print_help() + +if __name__ == '__main__': + main(sys.argv) From f4aa8821fb1d96335d7e213e471deccb48237517 Mon Sep 17 00:00:00 2001 From: Sergred Date: Sun, 12 Oct 2014 21:09:24 +0400 Subject: [PATCH 11/14] Added xsl file #1 --- xml/mephi#1.xsl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 xml/mephi#1.xsl diff --git a/xml/mephi#1.xsl b/xml/mephi#1.xsl new file mode 100644 index 0000000..4f43c6e --- /dev/null +++ b/xml/mephi#1.xsl @@ -0,0 +1,8 @@ + + + + + department #, + + + From f47d5e0a4296d67fc9ec77920102eb63ec46df85 Mon Sep 17 00:00:00 2001 From: Sergred Date: Sun, 12 Oct 2014 21:09:45 +0400 Subject: [PATCH 12/14] Added xsl file #3 --- xml/mephi.xsl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 xml/mephi.xsl diff --git a/xml/mephi.xsl b/xml/mephi.xsl new file mode 100644 index 0000000..5348098 --- /dev/null +++ b/xml/mephi.xsl @@ -0,0 +1,24 @@ + + + + + + +

Table of Students

+ + + + + + + + + + + +
StudentGroup
+ + +
+
+ From 27e750fbda72f32111a635aa57ad79ef54216b95 Mon Sep 17 00:00:00 2001 From: Sergred Date: Sun, 12 Oct 2014 21:10:04 +0400 Subject: [PATCH 13/14] Added html file --- xml/mephi.html | 129 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 xml/mephi.html diff --git a/xml/mephi.html b/xml/mephi.html new file mode 100644 index 0000000..daa1985 --- /dev/null +++ b/xml/mephi.html @@ -0,0 +1,129 @@ + +

Table of Students

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
StudentGroup
Дмитрий АртемьевK5-361
Наталья АнисимоваK5-361
Кирилл БубенкоK5-361
Алена ДжелоуховаK5-361
Айнур ЗамановK5-361
Денис МихеевK5-361
Александр ПивоваровK5-361
Артем СамсоновK5-361
Аня СоловьеваK5-361
Любовь СухановаK5-361
Евгений ТармазаковK5-361
Алексей ТиторенкоK5-361
Александр ШтанькоK5-361
Владислав АхметсафинK5-362
Александр ГалкинK5-362
Ирина ГоловкоK5-362
Евгений ДжумайлоK5-362
Владимир ЕрохинK5-362
Виктория КаталкинаK5-362
Андрей ЛевинK5-362
Ярослав МолочковK5-362
Виктория МоряшоваK5-362
Константин ПолстянкинK5-362
Яна ПурикK5-362
Никита РазживинK5-362
Сергей РедюкK5-362
Петр РябовK5-362
Дарья СкокK5-362
Олег СтрекаловK5-362
Александра ЧухненкоK5-362
+ From 791f3ca5a7f40e1752084f2c67f98c6a8b3aa6eb Mon Sep 17 00:00:00 2001 From: Sergred Date: Sun, 12 Oct 2014 21:10:24 +0400 Subject: [PATCH 14/14] Added txt file --- xml/mephi#1.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 xml/mephi#1.txt diff --git a/xml/mephi#1.txt b/xml/mephi#1.txt new file mode 100644 index 0000000..7504b9c --- /dev/null +++ b/xml/mephi#1.txt @@ -0,0 +1,2 @@ + +department #12, department #22, department #36,