From 6161a8366867356f5bb37491e095f9699b6ea3df Mon Sep 17 00:00:00 2001 From: luba Date: Tue, 9 Sep 2014 18:30:53 +0400 Subject: [PATCH 1/4] Adding of list --- mephi.xml | 12 ++++++++++++ programm_typing.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 mephi.xml create mode 100755 programm_typing.py diff --git a/mephi.xml b/mephi.xml new file mode 100644 index 0000000..2db4e3a --- /dev/null +++ b/mephi.xml @@ -0,0 +1,12 @@ + + + + + + Anisimova Natalia + Artemiev Dmitriy + Bubenko Kirill + + + + diff --git a/programm_typing.py b/programm_typing.py new file mode 100755 index 0000000..ed8b64b --- /dev/null +++ b/programm_typing.py @@ -0,0 +1,15 @@ +#! /usr/bin/env python +import sys, libxml2 + +def open(mephi_xml): + doc = libxml2.parseFile(mephi_xml) + 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) From ad20e32247605a66716adbfe43f0003f98eee98e Mon Sep 17 00:00:00 2001 From: luba Date: Tue, 16 Sep 2014 15:18:47 +0400 Subject: [PATCH 2/4] Renew adding list --- programm_typing.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/programm_typing.py b/programm_typing.py index ed8b64b..4411976 100755 --- a/programm_typing.py +++ b/programm_typing.py @@ -6,10 +6,15 @@ def open(mephi_xml): doc.freeDoc() def main(argv): - if len(argv) != 2: - sys.stderr.write("Usage : %s xml_file" % (argv[0],)) - else: - open(argv[1]) + 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) From 43b80f778d70cd30d574d017dc78a444c0c3ba9a Mon Sep 17 00:00:00 2001 From: luba Date: Tue, 16 Sep 2014 16:19:13 +0400 Subject: [PATCH 3/4] Adding of validate programm --- validate_xml.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 validate_xml.py 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() From 4b65960af8413c2e4410302998d597dbcc8d1c1b Mon Sep 17 00:00:00 2001 From: luba Date: Mon, 6 Oct 2014 21:05:22 +0400 Subject: [PATCH 4/4] Working with Xpath --- mephi.xml | 18 ++++++++++++++---- xpath.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 xpath.py diff --git a/mephi.xml b/mephi.xml index 2db4e3a..779af5e 100644 --- a/mephi.xml +++ b/mephi.xml @@ -1,11 +1,21 @@ - - - - + + + + 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/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)