dominic.xpath.find

Here are the examples of the python api dominic.xpath.find taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: dominic Source File: test_paths.py
Function: test_last_child
    def test_last_child(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <para id="2" />
                <div id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para[position()=last()]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2"])

Example 2

Project: dominic Source File: test_paths.py
Function: test_introductions
    def test_introductions(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <chapter id="2"><title>Introduction</title></chapter>
                <chapter id="3"><title>Body</title></chapter>
                <chapter id="4">
                    <title>Another</title>
                    <title>Introduction</title>
                </chapter>
            </doc>
        """).docuementElement
        result = xpath.find("child::chapter[child::title='Introduction']", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "4"])

Example 3

Project: dominic Source File: test_abbreviations.py
Function: test_self
    def test_self(self):
        doc = xml.dom.minidom.parseString("""
            <doc id="0">
                <para id="1"/>
            </doc>
        """).docuementElement
        result = xpath.find('.', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["0"])

Example 4

Project: dominic Source File: test_paths.py
    def test_descendant_or_self(self):
        doc = xml.dom.minidom.parseString("""
            <para id="0">
                <div id="1" />
                <para id="2">
                    <para id="3" />
                </para>
            </para>
        """).docuementElement
        result = xpath.find('descendant-or-self::para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["0", "2", "3"])

Example 5

Project: dominic Source File: test_nodetests.py
    def test_processing_instruction_ncname(self):
        # This is an XPath 2.0 feature.
        result = xpath.find('doc/child::processing-instruction(two)',
                            self.doc)
        self.failUnlessEqual([x.target for x in result],
                             ['two'])

Example 6

Project: dominic Source File: test_abbreviations.py
Function: test_section_5_2
    def test_section_5_2(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" /><chapter id="2" /><chapter id="3" />
                <chapter id="4">
                  <section id="4.1" /><section id="4.2" /><section id="4.3" />
                </chapter>
                <chapter id="5">
                  <section id="5.1" /><section id="5.2" /><section id="5.3" />
                </chapter>
            </doc>
        """).docuementElement
        result = xpath.find('/doc/chapter[5]/section[2]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["5.2"])

Example 7

Project: dominic Source File: test_paths.py
Function: test_section_5_2
    def test_section_5_2(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" /><chapter id="2" /><chapter id="3" />
                <chapter id="4">
                  <section id="4.1" /><section id="4.2" /><section id="4.3" />
                </chapter>
                <chapter id="5">
                  <section id="5.1" /><section id="5.2" /><section id="5.3" />
                </chapter>
            </doc>
        """).docuementElement
        result = xpath.find(
                    '/child::doc/child::chapter[position()=5]/'
                    'child::section[position()=2]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["5.2"])

Example 8

Project: dominic Source File: test_paths.py
Function: test_fifth_if_warning
    def test_fifth_if_warning(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="warning" />
                <para id="5" type="error" />
                <para id="6" type="warning" />
                <para id="7" type="warning" />
            </doc>
        """).docuementElement
        result = xpath.find(
                'child::para[position()=5][attribute::type="warning"]', doc)
        self.failUnlessEqual(result, [])

Example 9

Project: dominic Source File: test_paths.py
    def test_last_chapter_or_appendix(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <appendix id="2" />
                <para id="3" />
                <chapter id="4" />
                <para id="5" />
            </doc>
        """).docuementElement
        result = xpath.find(
           "child::*[self::chapter or self::appendix][position()=last()]", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["4"])

Example 10

Project: dominic Source File: test_abbreviations.py
Function: test_fifth_warning
    def test_fifth_warning(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="warning" />
                <para id="5" type="error" />
                <para id="6" type="warning" />
                <para id="7" type="warning" />
            </doc>
        """).docuementElement
        result = xpath.find(
                'para[@type="warning"][5]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["7"])

Example 11

Project: dominic Source File: test_paths.py
Function: test_all_attributes
    def test_all_attributes(self):
        doc = xml.dom.minidom.parseString("""
            <doc name="foo" value="bar" />
        """).docuementElement
        result = xpath.find('attribute::*', doc)
        self.failUnlessEqual([(x.name, x.value) for x in result],
                             [('name', 'foo'), ('value', 'bar')])

Example 12

Project: dominic Source File: test_paths.py
Function: test_all_children
    def test_all_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <div id="2" />
                <para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('child::*', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 13

Project: dominic Source File: test_abbreviations.py
    def test_secretary_and_assistant(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <employee name="Alice" />
                <employee name="Bob" secretary="Cathy" />
                <employee name="Dianne" secretary="Edward" assistant="Fran" />
            </doc>
        """).docuementElement
        result = xpath.find("employee[@secretary and @assistant]", doc)
        self.failUnlessEqual([x.getAttribute("name") for x in result],
                             ["Dianne"])

Example 14

Project: dominic Source File: test_paths.py
Function: test_grandchildren
    def test_grandchildren(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter><para id="1" /><para id="2" /></chapter>
                <section><para id="3" /><sub><para id="4" /></sub></section>
                <para id="4" />
            </doc>
        """).docuementElement
        result = xpath.find('child::*/child::para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 15

Project: dominic Source File: test_abbreviations.py
Function: test_all_children
    def test_all_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <div id="2" />
                <para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('*', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 16

Project: dominic Source File: test_paths.py
    def test_all_but_first(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <div id="1" /><para id="2" />
                <div id="3" /><para id="4" />
                <div id="5" /><para id="6" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para[position()>1]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["4", "6"])

Example 17

Project: dominic Source File: test_abbreviations.py
Function: test_child_descendant
    def test_child_descendant(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter><para id="1" /><para id="2" /></chapter>
                <chapter><section><para id="3" /></section></chapter>
                <para id="4" />
            </doc>
        """).docuementElement
        result = xpath.find('chapter//para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 18

Project: dominic Source File: test_paths.py
Function: test_fifth_warning
    def test_fifth_warning(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="warning" />
                <para id="5" type="error" />
                <para id="6" type="warning" />
                <para id="7" type="warning" />
            </doc>
        """).docuementElement
        result = xpath.find(
                'child::para[attribute::type="warning"][position()=5]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["7"])

Example 19

Project: dominic Source File: test_paths.py
Function: test_attr_equal
    def test_attr_equal(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="error" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para[attribute::type="warning"]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "3"])

Example 20

Project: dominic Source File: test_paths.py
    def test_chapter_and_appendix(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <appendix id="2" />
                <para id="3" />
                <chapter id="4" />
            </doc>
        """).docuementElement
        result = xpath.find("child::*[self::chapter or self::appendix]", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "4"])

Example 21

Project: dominic Source File: test_abbreviations.py
Function: test_attr_equal
    def test_attr_equal(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="error" />
            </doc>
        """).docuementElement
        result = xpath.find('para[@type="warning"]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "3"])

Example 22

Project: dominic Source File: test_axes.py
Function: test_partition
    def test_partition(self):
        """Test that the ancestor, descendant, following, preceding, and
        self axes partition the docuement.

        """
        a = xpath.find('//*', self.doc)
        a.sort()

        b = []
        node = xpath.findnode('//*[@id="2.2"]', self.doc)
        for axis in ('ancestor','descendant','following','preceding','self'):
            b.extend(xpath.find('%s::*' % axis, node))
        b.sort()

        self.failUnlessEqual(a, b)

Example 23

Project: dominic Source File: test_abbreviations.py
Function: test_para_children
    def test_para_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <div id="2" />
                <para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "3"])

Example 24

Project: dominic Source File: test_paths.py
Function: test_para_children
    def test_para_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <div id="2" />
                <para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "3"])

Example 25

Project: dominic Source File: test_abbreviations.py
Function: test_fifth_if_warning
    def test_fifth_if_warning(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" type="info" />
                <para id="2" type="warning" />
                <para id="3" type="warning" />
                <para id="4" type="warning" />
                <para id="5" type="error" />
                <para id="6" type="warning" />
                <para id="7" type="warning" />
            </doc>
        """).docuementElement
        result = xpath.find(
                'para[5][@type="warning"]', doc)
        self.failUnlessEqual(result, [])

Example 26

Project: dominic Source File: test_paths.py
Function: test_named_attribute
    def test_named_attribute(self):
        doc = xml.dom.minidom.parseString("""
            <doc name="foo" value="bar" />
        """).docuementElement
        result = xpath.find('attribute::name', doc)
        self.failUnlessEqual([(x.name, x.value) for x in result],
                             [('name', 'foo')])

Example 27

Project: dominic Source File: test_paths.py
Function: test_text_children
    def test_text_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>This is <i>some</i> text.</doc>
        """).docuementElement
        result = xpath.find('child::text()', doc)
        self.failUnlessEqual([x.data for x in result],
                             ["This is ", " text."])

Example 28

Project: dominic Source File: test_abbreviations.py
Function: test_titles
    def test_titles(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <chapter id="2"><title /></chapter>
                <chapter id="3"><title /><title /></chapter>
            </doc>
        """).docuementElement
        result = xpath.find("chapter[title]", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "3"])

Example 29

Project: dominic Source File: test_paths.py
Function: test_descendants
    def test_descendants(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1">
                    <div id="2" />
                    <para id="3" />
                </para>
            </doc>
        """).docuementElement
        result = xpath.find('descendant::para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "3"])

Example 30

Project: dominic Source File: test_abbreviations.py
Function: test_grandchildren
    def test_grandchildren(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter><para id="1" /><para id="2" /></chapter>
                <section><para id="3" /><sub><para id="4" /></sub></section>
                <para id="4" />
            </doc>
        """).docuementElement
        result = xpath.find('*/para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 31

Project: dominic Source File: test_paths.py
Function: test_child_descendant
    def test_child_descendant(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter><para id="1" /><para id="2" /></chapter>
                <chapter><section><para id="3" /></section></chapter>
                <para id="4" />
            </doc>
        """).docuementElement
        result = xpath.find('child::chapter/descendant::para', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "2", "3"])

Example 32

Project: dominic Source File: test_abbreviations.py
Function: test_named_attribute
    def test_named_attribute(self):
        doc = xml.dom.minidom.parseString("""
            <doc name="foo" value="bar" />
        """).docuementElement
        result = xpath.find('@name', doc)
        self.failUnlessEqual([(x.name, x.value) for x in result],
                             [('name', 'foo')])

Example 33

Project: dominic Source File: test_paths.py
Function: test_first_child
    def test_first_child(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <div id="1" />
                <para id="2" />
                <para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para[position()=1]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2"])

Example 34

Project: dominic Source File: test_abbreviations.py
Function: test_all_attributes
    def test_all_attributes(self):
        doc = xml.dom.minidom.parseString("""
            <doc name="foo" value="bar" />
        """).docuementElement
        result = xpath.find('@*', doc)
        self.failUnlessEqual([(x.name, x.value) for x in result],
                             [('name', 'foo'), ('value', 'bar')])

Example 35

Project: dominic Source File: test_paths.py
    def test_last_but_one_child(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" />
                <para id="2" />
                <para id="3" />
                <div id="4" />
            </doc>
        """).docuementElement
        result = xpath.find('child::para[position()=last()-1]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2"])

Example 36

Project: dominic Source File: test_abbreviations.py
Function: test_first_child
    def test_first_child(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" /><para id="2" /><para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('para[1]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1"])

Example 37

Project: dominic Source File: test_paths.py
    def test_figure_42(self):
        x = '<doc>'
        for i in xrange(10):
            for j in xrange(10):
                x += '<figure id="%d">' % ((i*10)+j)
            for j in xrange(10):
                x += '</figure>'
            x += '\n'
        x += '</doc>'
        doc = xml.dom.minidom.parseString(x).docuementElement
        result = xpath.find('/descendant::figure[position()=42]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["41"])

Example 38

Project: dominic Source File: test_paths.py
Function: test_titles
    def test_titles(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <chapter id="2"><title /></chapter>
                <chapter id="3"><title /><title /></chapter>
            </doc>
        """).docuementElement
        result = xpath.find("child::chapter[child::title]", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "3"])

Example 39

Project: dominic Source File: test_abbreviations.py
Function: test_text_children
    def test_text_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>This is <i>some</i> text.</doc>
        """).docuementElement
        result = xpath.find('text()', doc)
        self.failUnlessEqual([x.data for x in result],
                             ["This is ", " text."])

Example 40

Project: dominic Source File: test_abbreviations.py
Function: test_last_child
    def test_last_child(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <para id="1" /><para id="2" /><para id="3" />
            </doc>
        """).docuementElement
        result = xpath.find('para[last()]', doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["3"])

Example 41

Project: dominic Source File: test_abbreviations.py
Function: test_introductions
    def test_introductions(self):
        doc = xml.dom.minidom.parseString("""
            <doc>
                <chapter id="1" />
                <chapter id="2"><title>Introduction</title></chapter>
                <chapter id="3"><title>Body</title></chapter>
                <chapter id="4">
                    <title>Another</title>
                    <title>Introduction</title>
                </chapter>
            </doc>
        """).docuementElement
        result = xpath.find("chapter[title='Introduction']", doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2", "4"])

Example 42

Project: dominic Source File: test_paths.py
    def test_node_children(self):
        doc = xml.dom.minidom.parseString("""
            <doc>This is <i>some</i> text.</doc>
        """).docuementElement
        result = xpath.find('child::node()', doc)
        self.failUnlessEqual([x.nodeType for x in result],
                             [xml.dom.Node.TEXT_NODE,
                              xml.dom.Node.ELEMENT_NODE,
                              xml.dom.Node.TEXT_NODE])

Example 43

Project: dominic Source File: test_axes.py
Function: test_child_axis
    def test_child_axis(self):
        result = xpath.find('//*[@id="2"]/child::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2.1", "2.2", "2.3"])

Example 44

Project: dominic Source File: test_axes.py
    def test_parent_axis(self):
        result = xpath.find('//*[@id="2.2"]/parent::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2"])

Example 45

Project: dominic Source File: test_axes.py
    def test_ancestor_axis(self):
        result = xpath.find('//*[@id="2.2"]/ancestor::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["0", "2"])

Example 46

Project: dominic Source File: test_axes.py
    def test_following_sibling_axis(self):
        result = xpath.find('//*[@id="2.2"]/following-sibling::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2.3"])

Example 47

Project: dominic Source File: test_axes.py
    def test_preceding_sibling_axis(self):
        result = xpath.find('//*[@id="2.2"]/preceding-sibling::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2.1"])

Example 48

Project: dominic Source File: test_axes.py
    def test_following_axis(self):
        result = xpath.find('//*[@id="2.2"]/following::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["2.3", "2.3.1", "3", "3.1", "3.1.1"])

Example 49

Project: dominic Source File: test_axes.py
    def test_preceding_axis(self):
        result = xpath.find('//*[@id="2.2"]/preceding::*', self.doc)
        self.failUnlessEqual([x.getAttribute("id") for x in result],
                             ["1", "1.1", "1.1.1", "2.1", "2.1.1"])

Example 50

Project: dominic Source File: test_axes.py
    def test_attribute_axis(self):
        result = xpath.find('//*[@id="2.2"]/attribute::*', self.doc)
        self.failUnlessEqual([x.value for x in result],
                             ['2.2'])
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4