Example #1
0
    def fetch_text(xml_file):
        assert os.path.exists(xml_file)            
        def listener(path, element, filter):
            listener.text += element.text

        listener.text = ''            
        grabber = XmlGrabber()
        grabber.addXmlElementFilter(XmlPathFilter([ ".*/samenvatting", ".*/beschrijving", ".*/annotatie"]))
        grabber.grab(xml_file, listener)

        return listener.text
Example #2
0
    def fetch_text(xml_file):
        assert os.path.exists(xml_file)

        def listener(path, element, filter):
            listener.text += element.text

        listener.text = ''
        grabber = XmlGrabber()
        grabber.addXmlElementFilter(
            XmlPathFilter(
                [".*/samenvatting", ".*/beschrijving", ".*/annotatie"]))
        grabber.grab(xml_file, listener)

        return listener.text
Example #3
0
def fetch_text(xml_file):
    assert os.path.exists(xml_file)

    output_file_name = xml_file + ".txt"
    with codecs.open(output_file_name, "w", "utf-8") as f:

        def listener(path, element, filter):
            f.write(element.text)

        grabber = XmlGrabber()
        grabber.addXmlPathFilter(XmlPathFilter([".*/samenvatting"]))
        grabber.grab(xml_file, listener)

    return output_file_name
Example #4
0
 def test_xmlgrabber(self):
     global counter 
     
     def listener1(xml_path, element, filter):
         global counter
         counter += 1
     
     counter = 0
     grabber = XmlGrabber()
     grabber.addXmlElementFilter(XmlPathFilter([ ".*/selectiepositiedragerannotatie"  ]))
     grabber.grab(xml_file, listener1)
     self.assertEqual(0, counter)
     
     counter = 0
     grabber = XmlGrabber(False)
     grabber.addXmlElementFilter(XmlPathFilter(".*/selectiepositiedragerannotatie" ))
     grabber.grab(xml_file, listener1)
     self.assertEqual(1, counter)
Example #5
0
    def test_xml_elements_collector(self):
        def f1():
            g = XmlGrabber()
            b = XmlElementsCollector('root')
            g.addXmlElementFilter(TrueXmlElementFilter())
            g.grab(xml_file, b)

        self.assertRaises(NotImplementedError, f1)

        class MyXmlElementsCollector(XmlElementsCollector):
            def grabbed(self, path, element, filter):
                self.root_element().add_kid(element)

        g = XmlGrabber()
        b = MyXmlElementsCollector('root')
        g.addXmlElementFilter(TrueXmlElementFilter())
        g.grab(xml_file, b)

        self.assertEqual(len(str(b.root_element())), 10026)
Example #6
0
    def test_xml_elements_collector(self):
        def f1(): 
            g = XmlGrabber()
            b = XmlElementsCollector('root')
            g.addXmlElementFilter(TrueXmlElementFilter())
            g.grab(xml_file, b)
            
        self.assertRaises( NotImplementedError, f1)

        class MyXmlElementsCollector(XmlElementsCollector):
            def grabbed(self, path, element, filter):
                self.root_element().add_kid(element)

        g = XmlGrabber()
        b = MyXmlElementsCollector('root')
        g.addXmlElementFilter(TrueXmlElementFilter())
        g.grab(xml_file, b)
        
        self.assertEqual(len(str(b.root_element())), 10026)
Example #7
0
    def test_xmlgrabber(self):
        global counter

        def listener1(xml_path, element, filter):
            global counter
            counter += 1

        counter = 0
        grabber = XmlGrabber()
        grabber.addXmlElementFilter(
            XmlPathFilter([".*/selectiepositiedragerannotatie"]))
        grabber.grab(xml_file, listener1)
        self.assertEqual(0, counter)

        counter = 0
        grabber = XmlGrabber(False)
        grabber.addXmlElementFilter(
            XmlPathFilter(".*/selectiepositiedragerannotatie"))
        grabber.grab(xml_file, listener1)
        self.assertEqual(1, counter)
Example #8
0
 def f1():
     g = XmlGrabber()
     b = XmlElementsCollector('root')
     g.addXmlElementFilter(TrueXmlElementFilter())
     g.grab(xml_file, b)
Example #9
0
 def f1(): 
     g = XmlGrabber()
     b = XmlElementsCollector('root')
     g.addXmlElementFilter(TrueXmlElementFilter())
     g.grab(xml_file, b)