Commit 702a913f authored by Jiahang Chen's avatar Jiahang Chen
Browse files

ADD func get xml value

parent 0b99e4d9
Pipeline #469949 passed with stages
in 1 minute and 3 seconds
......@@ -125,6 +125,7 @@
from ml.ml40.features.functionalities.accepts_reports import AcceptsReports
from ml.ml40.features.functionalities.clears_jobs import ClearsJobs
from ml.ml40.features.functionalities.functionality import Functionality
from ml.ml40.features.functionalities.get_xml_value import GetXMLValue
from ml.ml40.features.functionalities.manages_jobs import ManagesJobs
from ml.ml40.features.functionalities.plans_routes import PlansRoutes
from ml.ml40.features.functionalities.provides_map_data import ProvidesMapData
......@@ -153,6 +154,7 @@
from ml.fml40.features.functionalities.forwards import Forwards
from ml.fml40.features.functionalities.generates_afforestation_suggestions import GeneratesAfforestationSuggestions
from ml.fml40.features.functionalities.generates_felling_suggestions import GeneratesFellingSuggestions
from ml.fml40.features.functionalities.get_stanford2010_value import GetStanForD2010Value
from ml.fml40.features.functionalities.grabs import Grabs
from ml.fml40.features.functionalities.harvests import Harvests
from ml.fml40.features.functionalities.measure_wood import MeasuresWood
......
from ml.ml40.features.functionalities.get_xml_value import GetXMLValue
class GetStanForD2010Value(GetXMLValue):
def __init__(self, name="", identifier=""):
super().__init__(
name=name,
identifier=identifier)
from ml.ml40.features.functionalities.functionality import Functionality
class GetXMLValue(Functionality):
def __init__(self, name="", identifier=""):
super().__init__(
name=name,
identifier=identifier)
def getValueByPath(self, XPath):
pass
\ No newline at end of file
......@@ -2,6 +2,7 @@
import json
import os
import xml.etree.ElementTree as ET
IDENTITY_PROVIDER_URL = "https://idp.s3i.vswf.dev/"
BUILT_IN = ["from", "str", "dict", "list", "bool", "float", "int", "tuple",
......@@ -169,4 +170,38 @@ def check_var_conflict(var):
if var in BUILT_IN:
return "_{}".format(var)
else:
return var
\ No newline at end of file
return var
class XML:
def __init__(self, path=None, xml_str=None):
self.et = ET
self._namespace = {}
self._namespace = {
'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'schemaLocation': 'urn:skogforsk:stanford2010 HarvestedProduction_V3p0.xsd',
'standford_ns': 'urn:skogforsk:stanford2010'
}
for key in self._namespace:
self.et.register_namespace(key, self._namespace[key])
if path is not None:
self.tree = self.et.parse(path)
self.root = self.tree.getroot()
if xml_str is not None:
self.root = self.et.fromstring(xml_str)
def find_nodes(self, path):
path_list = path.split('/')
new_path = ""
for _path in path_list:
if ":" not in _path:
_path = "standford_ns:{}".format(_path)
new_path += _path
new_path += "/"
if new_path[-1] == "/":
new_path = new_path[:-1]
return self.root.find(new_path, self._namespace)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment