|
|
@ -15,12 +15,9 @@
|
|
|
|
# limitations under the License.
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import lxml
|
|
|
|
|
|
|
|
from lxml import etree as ET
|
|
|
|
from lxml import etree as ET
|
|
|
|
from copy import deepcopy
|
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
|
|
|
|
# def appendChild(*args, **kwargs):
|
|
|
|
|
|
|
|
# ET._Element.append(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display_xml(xml):
|
|
|
|
def display_xml(xml):
|
|
|
|
print(xml_to_str(xml))
|
|
|
|
print(xml_to_str(xml))
|
|
|
@ -377,7 +374,7 @@ class xmlDoc():
|
|
|
|
newInsNode = deepcopy(nodeSeplist)
|
|
|
|
newInsNode = deepcopy(nodeSeplist)
|
|
|
|
self.setActionField(newInsNode, "append")
|
|
|
|
self.setActionField(newInsNode, "append")
|
|
|
|
|
|
|
|
|
|
|
|
if nextNode:
|
|
|
|
if nextNode is not None:
|
|
|
|
appSplLst.append((newInsNode,
|
|
|
|
appSplLst.append((newInsNode,
|
|
|
|
nextNode,
|
|
|
|
nextNode,
|
|
|
|
"insert"))
|
|
|
|
"insert"))
|
|
|
@ -389,7 +386,7 @@ class xmlDoc():
|
|
|
|
newInsNode = deepcopy(nodeSeplist)
|
|
|
|
newInsNode = deepcopy(nodeSeplist)
|
|
|
|
if self.getActionField(newInsNode) == "join":
|
|
|
|
if self.getActionField(newInsNode) == "join":
|
|
|
|
self.setActionField(newInsNode, "append")
|
|
|
|
self.setActionField(newInsNode, "append")
|
|
|
|
if xmlOldField:
|
|
|
|
if xmlOldField is not None:
|
|
|
|
insSplLst.append((newInsNode,
|
|
|
|
insSplLst.append((newInsNode,
|
|
|
|
xmlOldField,
|
|
|
|
xmlOldField,
|
|
|
|
"insert"))
|
|
|
|
"insert"))
|
|
|
@ -417,7 +414,7 @@ class xmlDoc():
|
|
|
|
flagCompareSeplist = True
|
|
|
|
flagCompareSeplist = True
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if not flagCompareSeplist:
|
|
|
|
if not flagCompareSeplist:
|
|
|
|
if xmlOldField:
|
|
|
|
if xmlOldField is not None:
|
|
|
|
insNodesRepl.append((newNode, nxtNode, app))
|
|
|
|
insNodesRepl.append((newNode, nxtNode, app))
|
|
|
|
|
|
|
|
|
|
|
|
for newNode, nxtNode, app in insNodesRepl:
|
|
|
|
for newNode, nxtNode, app in insNodesRepl:
|
|
|
@ -425,9 +422,9 @@ class xmlDoc():
|
|
|
|
insertBefore(xmlArea, newNode, nxtNode)
|
|
|
|
insertBefore(xmlArea, newNode, nxtNode)
|
|
|
|
elif app == "append":
|
|
|
|
elif app == "append":
|
|
|
|
xmlArea.append(newNode)
|
|
|
|
xmlArea.append(newNode)
|
|
|
|
if xmlOldField:
|
|
|
|
if xmlOldField is not None:
|
|
|
|
parentNode = xmlOldField.getparent()
|
|
|
|
parentNode = xmlOldField.getparent()
|
|
|
|
if parentNode and newFieldsAction != "join":
|
|
|
|
if parentNode is not None and newFieldsAction != "join":
|
|
|
|
parentNode.remove(xmlOldField)
|
|
|
|
parentNode.remove(xmlOldField)
|
|
|
|
|
|
|
|
|
|
|
|
for newNode, nxtNode, app in appSplLst:
|
|
|
|
for newNode, nxtNode, app in appSplLst:
|
|
|
@ -452,7 +449,7 @@ class xmlDoc():
|
|
|
|
if actionOldNode == "insert" or actionOldNode == "append":
|
|
|
|
if actionOldNode == "insert" or actionOldNode == "append":
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if nodeFieldOld.getnext() and \
|
|
|
|
if nodeFieldOld.getnext() is not None and \
|
|
|
|
self.getTypeField(
|
|
|
|
self.getTypeField(
|
|
|
|
nodeFieldOld.getnext()) == "br":
|
|
|
|
nodeFieldOld.getnext()) == "br":
|
|
|
|
xmlArea.remove(nodeFieldOld.getnext())
|
|
|
|
xmlArea.remove(nodeFieldOld.getnext())
|
|
|
@ -469,7 +466,7 @@ class xmlDoc():
|
|
|
|
if not nameField:
|
|
|
|
if not nameField:
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
parentNode = xmlField.getparent()
|
|
|
|
parentNode = xmlField.getparent()
|
|
|
|
if parentNode:
|
|
|
|
if parentNode is not None:
|
|
|
|
fieldsVal = xpath.Evaluate(
|
|
|
|
fieldsVal = xpath.Evaluate(
|
|
|
|
"child::field[attribute::type='seplist'][child::name='%s'] " \
|
|
|
|
"child::field[attribute::type='seplist'][child::name='%s'] " \
|
|
|
|
% nameField, parentNode)
|
|
|
|
% nameField, parentNode)
|
|
|
@ -814,7 +811,7 @@ class xmlDoc():
|
|
|
|
def getNameArea(self, xmlArea):
|
|
|
|
def getNameArea(self, xmlArea):
|
|
|
|
"""Выдает имя области"""
|
|
|
|
"""Выдает имя области"""
|
|
|
|
xmlNameAreas = xpath.Evaluate('child::caption/name', xmlArea)
|
|
|
|
xmlNameAreas = xpath.Evaluate('child::caption/name', xmlArea)
|
|
|
|
if xmlNameAreas and firstChild(xmlNameAreas[0]):
|
|
|
|
if xmlNameAreas and firstChild(xmlNameAreas[0]) is not None:
|
|
|
|
return firstChild(xmlNameAreas[0]).text
|
|
|
|
return firstChild(xmlNameAreas[0]).text
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -997,19 +994,19 @@ class xmlDoc():
|
|
|
|
for xmlField in xmlFields:
|
|
|
|
for xmlField in xmlFields:
|
|
|
|
xmlNames = xpath.Evaluate('child::name', xmlField)
|
|
|
|
xmlNames = xpath.Evaluate('child::name', xmlField)
|
|
|
|
xmlVals = xpath.Evaluate('child::value', xmlField)
|
|
|
|
xmlVals = xpath.Evaluate('child::value', xmlField)
|
|
|
|
# if xmlField.hasAttribute("type") and \
|
|
|
|
# if "type" in xmlField.keys() and \
|
|
|
|
# xmlField.getAttribute("type") == "br":
|
|
|
|
# xmlField.get("type") == "br":
|
|
|
|
if xmlField.get("type") == "br":
|
|
|
|
if xmlField.get("type") == "br":
|
|
|
|
lenBrArea += 1
|
|
|
|
lenBrArea += 1
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
if not xmlNames and not xmlVals:
|
|
|
|
if not xmlNames and not xmlVals:
|
|
|
|
flagListXml = False
|
|
|
|
flagListXml = False
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if xmlNames and firstChild(xmlNames[0]) and \
|
|
|
|
if xmlNames and firstChild(xmlNames[0]) is not None and \
|
|
|
|
firstChild(xmlNames[0]).text:
|
|
|
|
firstChild(xmlNames[0]).text:
|
|
|
|
flagListXml = False
|
|
|
|
flagListXml = False
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if not (xmlVals and firstChild(xmlVals[0]) and
|
|
|
|
if not (xmlVals and firstChild(xmlVals[0]) is not None and
|
|
|
|
firstChild(xmlVals[0]).text):
|
|
|
|
firstChild(xmlVals[0]).text):
|
|
|
|
flagListXml = False
|
|
|
|
flagListXml = False
|
|
|
|
break
|
|
|
|
break
|
|
|
|