Commit 601a1d9c authored by Nicolas Delaby's avatar Nicolas Delaby

Replace libxml2 library by lxml

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31606 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a2d5f88a
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2007-2008 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2007-2008 Nexedi SA and Contributors. All Rights Reserved.
...@@ -31,15 +32,7 @@ from Products.ERP5Type.Globals import InitializeClass ...@@ -31,15 +32,7 @@ from Products.ERP5Type.Globals import InitializeClass
from DocumentationHelper import DocumentationHelper from DocumentationHelper import DocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from lxml import etree
# XXX Use lxml instead.
try:
from libxml2 import parseDoc, parserError
import_succeed = 1
except ImportError:
from xml.dom.minidom import parseString
from xml.xpath import Evaluate
import_succeed = 0
class PortalTypePropertySheetDocumentationHelper(DocumentationHelper): class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
""" """
...@@ -103,28 +96,18 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper): ...@@ -103,28 +96,18 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
filename=self.title_or_id() filename=self.title_or_id()
) )
xpath = '//*[name() = "office:text"]//*[name() = "text:p"]' xpath = '//*[name() = "office:text"]//*[name() = "text:p"]'
if import_succeed: # parse content.xml
#libxml2 xml_doc = etree.fromstring(source_xml)
# parse content.xml # the namespace text
xml_doc = parseDoc(source_xml) text_ns = xml_doc.nsmap['text']
# the name space text # all element text:p
text_ns = xml_doc.getRootElement().searchNs(xml_doc, 'text') text_list = xml_doc.xpath(xpath, namespaces=xml_doc.nsmap)
# all element text:p # all element wich have an text:style-name attribute
text_list = xml_doc.xpathEval(xpath) parent_tag_list = xml_doc.xpath('//*[@*[name() = "text:style-name"]]', namespaces=xml_doc.nsmap)
# all element wich have an text:style-name attribut # Change the attribute text:style-name with a default value
parent_tag_list = xml_doc.xpathEval('//*[@*[name() = "text:style-name"]]') [parent_tag.attrib.update({'{%s}style-name' % text_ns: 'Preformatted_20_Text'}) \
# Change the attribut text:style-name with a default value
[parent_tag.setNsProp(text_ns, 'style-name', 'Preformatted_20_Text') \
for parent_tag in parent_tag_list] for parent_tag in parent_tag_list]
xml = ''.join([text.serialize('utf-8', 0) for text in text_list]) return ''.join([etree.tostring(text, pretty_print=True) for text in text_list])
xml_doc.freeDoc()
return xml
else:
# minidom
xml_doc = parseString(source_xml)
tag_list = Evaluate (xpath , xml_doc)
xml = ''.join(tag.toxml('utf-8') for tag in tag_list)
return xml
else: else:
return source_code return source_code
......
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