예제 #1
0
파일: idml.py 프로젝트: Starou/SimpleIDML
        def _import_new_node(source_node, at=None, element_id=None, story=None):
            xml_structure_parent_node = self.xml_structure.find("*//*[@Self='%s']" % element_id)
            xml_structure_new_node = etree.Element(source_node.tag)
            # We cannot force the self._xml_structure reset by setting it at None.
            xml_structure_parent_node.append(xml_structure_new_node)

            style_range_node, applied_style_node = _get_nested_style_range_node(xml_structure_new_node)
            story = story or self.get_story_object_by_xpath(at)
            parent = story.get_element_by_id(element_id)
            _apply_parent_style_range(style_range_node, applied_style_node, parent)

            new_xml_element = XMLElement(tag=source_node.tag)
            new_xml_element.add_content(source_node.text, parent, style_range_node)
            story.add_element(element_id, new_xml_element.element)

            xml_structure_new_node.set("Self", new_xml_element.get("Self"))

            # Source may also contains some children.
            source_node_children = source_node.getchildren()
            if len(source_node_children):
                story.synchronize()
                for j, source_node_child in enumerate(source_node_children):
                    _import_new_node(source_node_child,
                                     element_id=new_xml_element.get("Self"),
                                     story=story)

            if source_node.tail:
                story.add_content_to_element(element_id, source_node.tail, parent)
            story.synchronize()
예제 #2
0
파일: idml.py 프로젝트: mnvx/SimpleIDML
        def _import_new_node(source_node,
                             at=None,
                             element_id=None,
                             story=None):
            xml_structure_parent_node = self.xml_structure.find(
                "*//*[@Self='%s']" % element_id)
            xml_structure_new_node = etree.Element(source_node.tag)
            # We cannot force the self._xml_structure reset by setting it at None.
            xml_structure_parent_node.append(xml_structure_new_node)

            style_range_node, applied_style_node = _get_nested_style_range_node(
                xml_structure_new_node)
            story = story or self.get_story_object_by_xpath(at)
            parent = story.get_element_by_id(element_id)
            _apply_parent_style_range(style_range_node, applied_style_node,
                                      parent)

            new_xml_element = XMLElement(tag=source_node.tag)
            new_xml_element.add_content(source_node.text, parent,
                                        style_range_node)
            story.add_element(element_id, new_xml_element.element)

            xml_structure_new_node.set("Self", new_xml_element.get("Self"))

            # Source may also contains some children.
            source_node_children = source_node.getchildren()
            if len(source_node_children):
                story.synchronize()
                for j, source_node_child in enumerate(source_node_children):
                    _import_new_node(source_node_child,
                                     element_id=new_xml_element.get("Self"),
                                     story=story)

            if source_node.tail:
                story.add_content_to_element(element_id, source_node.tail,
                                             parent)
            story.synchronize()