diff --git a/Backend-libXML/.gitignore b/Backend-libXML/.gitignore new file mode 100644 index 0000000..9ca9383 --- /dev/null +++ b/Backend-libXML/.gitignore @@ -0,0 +1,3 @@ +.idea +__pycache** +venv diff --git a/Backend-libXML/Parser.py b/Backend-libXML/Parser.py index ca60571..a76f67d 100644 --- a/Backend-libXML/Parser.py +++ b/Backend-libXML/Parser.py @@ -4,20 +4,24 @@ from lxml import etree def xpath(source: str, xpath: str) -> str: """ Method used to get nodes from XML string using XPath + :param source: XML string used for selection + :type source: str :param xpath: XPath query used for selection + :type xpath: str :return: Nodes selected using XPath + :rtype: str """ + + root = etree.XML(source) nsmap = root.nsmap # LXML doesn't accept namespace with None key, # so it need to be deleted if exists - try: + if None in nsmap: nsmap.pop(None) - except KeyError: - print(end="") - + result = root.xpath(xpath, namespaces=nsmap) result_string = "" for e in result: @@ -30,8 +34,11 @@ def xsd(source: str, xsd: str) -> bool: """ Method used to validate XML string against XSD schema :param source: XML string used for validation + :type source: str :param xsd: XSD schema to validate XML against + :type xsd: str :return: If the validation was successful or not + :rtype: bool """ xml_schema = etree.XMLSchema(etree.XML(xsd)) @@ -43,9 +50,13 @@ def xsd(source: str, xsd: str) -> bool: def xslt(source: str, xslt: str) -> str: """ Method used to transformate XML string using XSLT - :param source: Transformed XML string + + :param source: XML string to transform + :type source: str :param xslt: XSLT string used to transformate XML + :type xslt: str :return: Result of transformation + :rtype: str """ xslt_transform = etree.XSLT(etree.XML(xslt)) diff --git a/Backend-libXML/__pycache__/Parser.cpython-310.pyc b/Backend-libXML/__pycache__/Parser.cpython-310.pyc deleted file mode 100644 index a6014e1..0000000 Binary files a/Backend-libXML/__pycache__/Parser.cpython-310.pyc and /dev/null differ diff --git a/Backend-libXML/__pycache__/server.cpython-310.pyc b/Backend-libXML/__pycache__/server.cpython-310.pyc deleted file mode 100644 index 6fdb3a0..0000000 Binary files a/Backend-libXML/__pycache__/server.cpython-310.pyc and /dev/null differ diff --git a/Backend-libXML/sample/xpath.json b/Backend-libXML/sample/xpath.json deleted file mode 100644 index 70faa16..0000000 --- a/Backend-libXML/sample/xpath.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", - "process": "/books/book[name = 'The Law of Success']", - "processor": "saxon", - "version": "2.0" -} diff --git a/Backend-libXML/sample/xpath/data.json b/Backend-libXML/sample/xpath/data.json new file mode 100644 index 0000000..2de1632 --- /dev/null +++ b/Backend-libXML/sample/xpath/data.json @@ -0,0 +1,6 @@ +{ + "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", + "process": "/books/book[name = 'The Law of Success']", + "processor": "saxon", + "version": "2.0" +} diff --git a/Backend-libXML/sample/xpath/dataNS.json b/Backend-libXML/sample/xpath/dataNS.json new file mode 100644 index 0000000..ec5eb94 --- /dev/null +++ b/Backend-libXML/sample/xpath/dataNS.json @@ -0,0 +1,6 @@ +{ + "data": "Hamlet2001-05-041falseMacbeth2000-12-131falseHarry Potter and the Sorcerer's Stone2005-04-292trueThe Long Walk2018-07-014trueMisery2018-01-314trueThink and Grow Rich2004-09-106trueThe Law of Success1982-05-096falsePatriot Games1995-10-215falseThe Sum of All Fears1992-09-195falseThe Alchemist2017-02-203falseHamlet1994-06-011falseMeasure for Measure1990-03-231falseHamlet1989-05-051trueHamlet1999-05-301trueThe Law of Success2004-11-266trueRomeo and Juliet1997-02-081trueThe Alchemist2009-08-213true", + "process": "/b:books/b:book[b:name = 'The Law of Success']", + "processor": "saxon", + "version": "2.0" +} diff --git a/Backend-libXML/sample/xpath.curl b/Backend-libXML/sample/xpath/non-ns.conf similarity index 85% rename from Backend-libXML/sample/xpath.curl rename to Backend-libXML/sample/xpath/non-ns.conf index f72790a..064cfbf 100644 --- a/Backend-libXML/sample/xpath.curl +++ b/Backend-libXML/sample/xpath/non-ns.conf @@ -1,5 +1,5 @@ #url = "localhost:8081/xpathpost" url = "localhost:5000/xpath" request = "POST" -data = "@xpath.json" +data = "@data.json" header = "Content-Type: application/json" diff --git a/Backend-libXML/sample/xpath/ns.conf b/Backend-libXML/sample/xpath/ns.conf new file mode 100644 index 0000000..6f098cc --- /dev/null +++ b/Backend-libXML/sample/xpath/ns.conf @@ -0,0 +1,5 @@ +#url = "localhost:8081/xpathpost" +url = "localhost:5000/xpath" +request = "POST" +data = "@dataNS.json" +header = "Content-Type: application/json" diff --git a/Backend-libXML/sample/xsd.curl b/Backend-libXML/sample/xsd/xsd.curl similarity index 52% rename from Backend-libXML/sample/xsd.curl rename to Backend-libXML/sample/xsd/xsd.curl index 9c1ce6a..b9e65d1 100644 --- a/Backend-libXML/sample/xsd.curl +++ b/Backend-libXML/sample/xsd/xsd.curl @@ -1,4 +1,5 @@ -url = "http://localhost:8082/xsd" +#url = "http://localhost:8082/xsd" +url = "http://localhost:5000/xsd" data = "@xsd.json" header = "Content-Type: application/json" request = POST diff --git a/Backend-libXML/sample/xsd.json b/Backend-libXML/sample/xsd/xsd.json similarity index 100% rename from Backend-libXML/sample/xsd.json rename to Backend-libXML/sample/xsd/xsd.json diff --git a/Backend-libXML/sample/xslt.curl b/Backend-libXML/sample/xslt/xslt.curl similarity index 100% rename from Backend-libXML/sample/xslt.curl rename to Backend-libXML/sample/xslt/xslt.curl diff --git a/Backend-libXML/sample/xslt.json b/Backend-libXML/sample/xslt/xslt.json similarity index 100% rename from Backend-libXML/sample/xslt.json rename to Backend-libXML/sample/xslt/xslt.json