gorram it lxml.

This commit is contained in:
brent s. 2018-05-26 09:11:07 -04:00
parent ee653e81f6
commit 7c0c7bf5c0
2 changed files with 3 additions and 10 deletions

View File

@ -308,19 +308,11 @@ class Conf(object):


def validate(self): def validate(self):
# TODO: perform further validations that we can't do in XSD. # TODO: perform further validations that we can't do in XSD.
# TODO: FIX ME. ALWAYS RETURNS INVALID:
# lxml.etree.DocumentInvalid: Element 'bdisk': No matching global declaration available for the validation root.
xsd = self.get_xsd() xsd = self.get_xsd()
self.xsd = etree.XMLSchema(xsd) self.xsd = etree.XMLSchema(xsd)
# This would return a bool if it validates or not. # This would return a bool if it validates or not.
#self.xsd.validate(self.xml) #self.xsd.validate(self.xml)
# We want to get a more detailed exception. # We want to get a more detailed exception.
#xml = self.xml_suppl.return_full().getroottree() xml = etree.fromstring(self.xml_suppl.return_full())
xml = self.xml_suppl.return_full()
with open('/tmp/bdisk.xml', 'wb') as f:
f.write(etree.tostring(xml))
with open('/tmp/bdisk.xsd', 'wb') as f:
f.write(etree.tostring(xsd))
self.xsd.assertValid(xml) self.xsd.assertValid(xml)
#print(self.xsd.validate(xml))
return() return()

View File

@ -977,13 +977,14 @@ class xml_supplicant(object):


def return_full(self): def return_full(self):
#nsmap = self.return_naked_ns() #nsmap = self.return_naked_ns()
# https://stackoverflow.com/a/22553145/733214
local_xml = lxml.etree.Element('bdisk', local_xml = lxml.etree.Element('bdisk',
nsmap = self.orig_xml.nsmap, nsmap = self.orig_xml.nsmap,
attrib = self.orig_xml.attrib) attrib = self.orig_xml.attrib)
local_xml.text = '\n ' local_xml.text = '\n '
for elem in self.xml.xpath('/bdisk/profile'): for elem in self.xml.xpath('/bdisk/profile'):
local_xml.append(copy.deepcopy(elem)) local_xml.append(copy.deepcopy(elem))
return(local_xml) return(lxml.etree.tostring(local_xml))


def return_naked_ns(self): def return_naked_ns(self):
# It's so stupid I have to do this. # It's so stupid I have to do this.