Exemplo n.º 1
0
 def export_xml(self, from_tag=None, encoding=None):
     """ Reproduce the action «Export XML» on a XML Element in InDesign® Structure. """
     tree = self.export_as_tree()
     dom = tree_to_etree_dom(tree)
     return etree.tostring(dom, encoding=encoding, pretty_print=True).decode("utf-8")
Exemplo n.º 2
0
    def test_tree_to_etree_dom(self):
        from simple_idml.utils import tree_to_etree_dom
        tree = {
            'tag':
            'Root',
            'attrs': {},
            'content': [{
                'tag':
                'module',
                'attrs': {},
                'content': [{
                    'tag': 'main_picture',
                    'attrs': {
                        'href': 'file:///steve.jpg'
                    },
                    'content': [],
                }, {
                    'tag': 'headline',
                    'attrs': {},
                    'content': ['The Life Aquatic with Steve Zissou'],
                }, {
                    'tag':
                    'Story',
                    'attrs': {},
                    'content': [{
                        'tag':
                        'article',
                        'attrs': {},
                        'content': [
                            'While oceanographer and documentarian ', {
                                'tag':
                                'bold',
                                'attrs': {},
                                'content': [
                                    'Steve Zissou (Bill Murray) is ',
                                    {
                                        'tag': 'sup',
                                        'attrs': {},
                                        'content': ['working'],
                                    },
                                    ' on his latest documentary at sea, his best friend ',
                                    {
                                        'tag': 'italique',
                                        'attrs': {},
                                        'content': ['Esteban du Plantier'],
                                    },
                                    ' (Seymour Cassel)',
                                ],
                            },
                            u' is eaten by a creature Zissou describes as a "Jaguar shark."',
                            {
                                'tag': 'italique',
                                'attrs': {},
                                'content': ['Belafonte'],
                            }, ' includes ', {
                                'tag': 'italique',
                                'attrs': {},
                                'content': [u'Pel\xe9 dos Santos (Seu Jorge)'],
                            },
                            ', a safety expert and Brazilian musician who sings David Bowie songs in Portuguese.'
                        ],
                    }, {
                        'tag':
                        'informations',
                        'attrs': {},
                        'content': [
                            'The Life Aquatic with Steve Zissou is an American comedy-drama film.'
                        ],
                    }],
                }],
            }],
        }
        dom = tree_to_etree_dom(tree)
        self.assertMultiLineEqual(
            etree.tostring(dom, pretty_print=True).decode("utf-8"), """<Root>
  <module>
    <main_picture href="file:///steve.jpg"/>
    <headline>The Life Aquatic with Steve Zissou</headline>
    <Story>
      <article>While oceanographer and documentarian <bold>Steve Zissou (Bill Murray) is <sup>working</sup> on his latest documentary at sea, his best friend <italique>Esteban du Plantier</italique> (Seymour Cassel)</bold> is eaten by a creature Zissou describes as a "Jaguar shark."<italique>Belafonte</italique> includes <italique>Pel&#233; dos Santos (Seu Jorge)</italique>, a safety expert and Brazilian musician who sings David Bowie songs in Portuguese.</article>
      <informations>The Life Aquatic with Steve Zissou is an American comedy-drama film.</informations>
    </Story>
  </module>
</Root>
""")
Exemplo n.º 3
0
 def export_xml(self, from_tag=None, encoding=None):
     """ Reproduce the action «Export XML» on a XML Element in InDesign® Structure. """
     tree = self.export_as_tree()
     dom = tree_to_etree_dom(tree)
     return etree.tostring(dom, encoding=encoding, pretty_print=True)
Exemplo n.º 4
0
    def test_tree_to_etree_dom(self):
        from simple_idml.utils import tree_to_etree_dom
        tree = {
            'tag': 'Root',
            'attrs': {},
            'content': [
                {
                    'tag': 'module',
                    'attrs': {},
                    'content': [
                        {
                            'tag': 'main_picture',
                            'attrs': {'href': 'file:///steve.jpg'},
                            'content': [],
                        },
                        {
                            'tag': 'headline',
                            'attrs': {},
                            'content': ['The Life Aquatic with Steve Zissou'],
                        },
                        {
                            'tag': 'Story',
                            'attrs': {},
                            'content': [
                                {
                                    'tag': 'article',
                                    'attrs': {},
                                    'content': [
                                        'While oceanographer and documentarian ',
                                        {
                                            'tag': 'bold',
                                            'attrs': {},
                                            'content': [
                                                'Steve Zissou (Bill Murray) is ',
                                                {
                                                    'tag': 'sup',
                                                    'attrs': {},
                                                    'content': ['working'],
                                                },
                                                ' on his latest documentary at sea, his best friend ',
                                                {
                                                    'tag': 'italique',
                                                    'attrs': {},
                                                    'content': ['Esteban du Plantier'],
                                                },
                                                ' (Seymour Cassel)',
                                            ],
                                        },
                                        u' is eaten by a creature Zissou describes as a "Jaguar shark."',
                                        {
                                            'tag': 'italique',
                                            'attrs': {},
                                            'content': ['Belafonte'],
                                        },
                                        ' includes ',
                                        {
                                            'tag': 'italique',
                                            'attrs': {},
                                            'content': [u'Pel\xe9 dos Santos (Seu Jorge)'],
                                        },
                                        ', a safety expert and Brazilian musician who sings David Bowie songs in Portuguese.'
                                    ],
                                },
                                {
                                    'tag': 'informations',
                                    'attrs': {},
                                    'content': [
                                        'The Life Aquatic with Steve Zissou is an American comedy-drama film.'
                                    ],
                                }
                            ],
                        }
                    ],
                }
            ],
        }
        dom = tree_to_etree_dom(tree)
        self.assertMultiLineEqual(etree.tostring(dom, pretty_print=True).decode("utf-8"),
"""<Root>
  <module>
    <main_picture href="file:///steve.jpg"/>
    <headline>The Life Aquatic with Steve Zissou</headline>
    <Story>
      <article>While oceanographer and documentarian <bold>Steve Zissou (Bill Murray) is <sup>working</sup> on his latest documentary at sea, his best friend <italique>Esteban du Plantier</italique> (Seymour Cassel)</bold> is eaten by a creature Zissou describes as a "Jaguar shark."<italique>Belafonte</italique> includes <italique>Pel&#233; dos Santos (Seu Jorge)</italique>, a safety expert and Brazilian musician who sings David Bowie songs in Portuguese.</article>
      <informations>The Life Aquatic with Steve Zissou is an American comedy-drama film.</informations>
    </Story>
  </module>
</Root>
""")