dev #26
							
								
								
									
										3
									
								
								Backend-libXML/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Backend-libXML/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| .idea | ||||
| __pycache** | ||||
| venv | ||||
| @@ -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)) | ||||
|  | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1,6 +0,0 @@ | ||||
| { | ||||
|   "data": "<?xml version='1.0' encoding='utf-8'?><books><book id='1'><name>Hamlet</name><date>2001-05-04</date><authorId>1</authorId><availability>false</availability></book><book id='2'><name>Macbeth</name><date>2000-12-13</date><authorId>1</authorId><availability>false</availability></book><book id='3'><name>Harry Potter and the Sorcerer's Stone</name><date>2005-04-29</date><authorId>2</authorId><availability>true</availability></book><book id='4'><name>The Long Walk</name><date>2018-07-01</date><authorId>4</authorId><availability>true</availability></book><book id='5'><name>Misery</name><date>2018-01-31</date><authorId>4</authorId><availability>true</availability></book><book id='6'><name>Think and Grow Rich</name><date>2004-09-10</date><authorId>6</authorId><availability>true</availability></book><book id='7'><name>The Law of Success</name><date>1982-05-09</date><authorId>6</authorId><availability>false</availability></book><book id='8'><name>Patriot Games</name><date>1995-10-21</date><authorId>5</authorId><availability>false</availability></book><book id='9'><name>The Sum of All Fears</name><date>1992-09-19</date><authorId>5</authorId><availability>false</availability></book><book id='10'><name>The Alchemist</name><date>2017-02-20</date><authorId>3</authorId><availability>false</availability></book><book id='11'><name>Hamlet</name><date>1994-06-01</date><authorId>1</authorId><availability>false</availability></book><book id='12'><name>Measure for Measure</name><date>1990-03-23</date><authorId>1</authorId><availability>false</availability></book><book id='13'><name>Hamlet</name><date>1989-05-05</date><authorId>1</authorId><availability>true</availability></book><book id='14'><name>Hamlet</name><date>1999-05-30</date><authorId>1</authorId><availability>true</availability></book><book id='15'><name>The Law of Success</name><date>2004-11-26</date><authorId>6</authorId><availability>true</availability></book><book id='16'><name>Romeo and Juliet</name><date>1997-02-08</date><authorId>1</authorId><availability>true</availability></book><book id='17'><name>The Alchemist</name><date>2009-08-21</date><authorId>3</authorId><availability>true</availability></book></books>", | ||||
|   "process": "/books/book[name = 'The Law of Success']", | ||||
|   "processor": "saxon", | ||||
|   "version": "2.0" | ||||
| } | ||||
							
								
								
									
										6
									
								
								Backend-libXML/sample/xpath/data.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Backend-libXML/sample/xpath/data.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| { | ||||
|   "data": "<books><book id='1'><name>Hamlet</name><date>2001-05-04</date><authorId>1</authorId><availability>false</availability></book><book id='2'><name>Macbeth</name><date>2000-12-13</date><authorId>1</authorId><availability>false</availability></book><book id='3'><name>Harry Potter and the Sorcerer's Stone</name><date>2005-04-29</date><authorId>2</authorId><availability>true</availability></book><book id='4'><name>The Long Walk</name><date>2018-07-01</date><authorId>4</authorId><availability>true</availability></book><book id='5'><name>Misery</name><date>2018-01-31</date><authorId>4</authorId><availability>true</availability></book><book id='6'><name>Think and Grow Rich</name><date>2004-09-10</date><authorId>6</authorId><availability>true</availability></book><book id='7'><name>The Law of Success</name><date>1982-05-09</date><authorId>6</authorId><availability>false</availability></book><book id='8'><name>Patriot Games</name><date>1995-10-21</date><authorId>5</authorId><availability>false</availability></book><book id='9'><name>The Sum of All Fears</name><date>1992-09-19</date><authorId>5</authorId><availability>false</availability></book><book id='10'><name>The Alchemist</name><date>2017-02-20</date><authorId>3</authorId><availability>false</availability></book><book id='11'><name>Hamlet</name><date>1994-06-01</date><authorId>1</authorId><availability>false</availability></book><book id='12'><name>Measure for Measure</name><date>1990-03-23</date><authorId>1</authorId><availability>false</availability></book><book id='13'><name>Hamlet</name><date>1989-05-05</date><authorId>1</authorId><availability>true</availability></book><book id='14'><name>Hamlet</name><date>1999-05-30</date><authorId>1</authorId><availability>true</availability></book><book id='15'><name>The Law of Success</name><date>2004-11-26</date><authorId>6</authorId><availability>true</availability></book><book id='16'><name>Romeo and Juliet</name><date>1997-02-08</date><authorId>1</authorId><availability>true</availability></book><book id='17'><name>The Alchemist</name><date>2009-08-21</date><authorId>3</authorId><availability>true</availability></book></books>", | ||||
|   "process": "/books/book[name = 'The Law of Success']", | ||||
|   "processor": "saxon", | ||||
|   "version": "2.0" | ||||
| } | ||||
							
								
								
									
										6
									
								
								Backend-libXML/sample/xpath/dataNS.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Backend-libXML/sample/xpath/dataNS.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| { | ||||
|   "data": "<b:books xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.demo.com' xmlns:b='http://www.book.com' xmlns:a='http://www.author.com'><b:book id='1'><b:name>Hamlet</b:name><b:date>2001-05-04</b:date><a:authorId>1</a:authorId><b:availability>false</b:availability></b:book><b:book id='2'><b:name>Macbeth</b:name><b:date>2000-12-13</b:date><a:authorId>1</a:authorId><b:availability>false</b:availability></b:book><b:book id='3'><b:name>Harry Potter and the Sorcerer's Stone</b:name><b:date>2005-04-29</b:date><a:authorId>2</a:authorId><b:availability>true</b:availability></b:book><b:book id='4'><b:name>The Long Walk</b:name><b:date>2018-07-01</b:date><a:authorId>4</a:authorId><b:availability>true</b:availability></b:book><b:book id='5'><b:name>Misery</b:name><b:date>2018-01-31</b:date><a:authorId>4</a:authorId><b:availability>true</b:availability></b:book><b:book id='6'><b:name>Think and Grow Rich</b:name><b:date>2004-09-10</b:date><a:authorId>6</a:authorId><b:availability>true</b:availability></b:book><b:book id='7'><b:name>The Law of Success</b:name><b:date>1982-05-09</b:date><a:authorId>6</a:authorId><b:availability>false</b:availability></b:book><b:book id='8'><b:name>Patriot Games</b:name><b:date>1995-10-21</b:date><a:authorId>5</a:authorId><b:availability>false</b:availability></b:book><b:book id='9'><b:name>The Sum of All Fears</b:name><b:date>1992-09-19</b:date><a:authorId>5</a:authorId><b:availability>false</b:availability></b:book><b:book id='10'><b:name>The Alchemist</b:name><b:date>2017-02-20</b:date><a:authorId>3</a:authorId><b:availability>false</b:availability></b:book><b:book id='11'><b:name>Hamlet</b:name><b:date>1994-06-01</b:date><a:authorId>1</a:authorId><b:availability>false</b:availability></b:book><b:book id='12'><b:name>Measure for Measure</b:name><b:date>1990-03-23</b:date><a:authorId>1</a:authorId><b:availability>false</b:availability></b:book><b:book id='13'><b:name>Hamlet</b:name><b:date>1989-05-05</b:date><a:authorId>1</a:authorId><b:availability>true</b:availability></b:book><b:book id='14'><b:name>Hamlet</b:name><b:date>1999-05-30</b:date><a:authorId>1</a:authorId><b:availability>true</b:availability></b:book><b:book id='15'><b:name>The Law of Success</b:name><b:date>2004-11-26</b:date><a:authorId>6</a:authorId><b:availability>true</b:availability></b:book><b:book id='16'><b:name>Romeo and Juliet</b:name><b:date>1997-02-08</b:date><a:authorId>1</a:authorId><b:availability>true</b:availability></b:book><b:book id='17'><b:name>The Alchemist</b:name><b:date>2009-08-21</b:date><a:authorId>3</a:authorId><b:availability>true</b:availability></b:book></b:books>", | ||||
|   "process": "/b:books/b:book[b:name = 'The Law of Success']", | ||||
|   "processor": "saxon", | ||||
|   "version": "2.0" | ||||
| } | ||||
| @@ -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" | ||||
							
								
								
									
										5
									
								
								Backend-libXML/sample/xpath/ns.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								Backend-libXML/sample/xpath/ns.conf
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| #url = "localhost:8081/xpathpost" | ||||
| url = "localhost:5000/xpath" | ||||
| request = "POST" | ||||
| data = "@dataNS.json" | ||||
| header = "Content-Type: application/json" | ||||
| @@ -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 | ||||
		Reference in New Issue
	
	Block a user