Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / MetadataGetter.groovy @ 187

History | View | Annotate | Download (1 kB)

1
package org.txm.importer
2

    
3
import javax.xml.stream.*;
4

    
5
class MetadataGetter {
6
        public static String get(File xmlFile, String struct, String prop) {
7

    
8
                def inputData = xmlFile.toURI().toURL().openStream();
9
                def factory = XMLInputFactory.newInstance();
10
                XMLStreamReader parser = factory.createXMLStreamReader(inputData);
11

    
12
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
13
                        if (event == XMLStreamConstants.START_ELEMENT) {
14
                                if ("text".equals(parser.getLocalName())) {
15
                                        for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
16
                                                if(prop.equals(parser.getAttributeLocalName(i))) {
17
                                                        String tmp = parser.getAttributeValue(i)
18
                                                        parser.close()
19
                                                        return tmp
20
                                                }
21
                                        }
22
                                }
23
                        }
24
                }
25
                parser.close()
26
                return null;
27
        }
28

    
29
        public static void main(String[] args) {
30
                File xmlFile = new File("/home/mdecorde/TXM/corpora/superphenix/txm/SUPERPHENIX/CreysSuper_04_0175.xml")
31
                String struct = "text"
32
                String prop = "date"
33
                println MetadataGetter.get(xmlFile, struct, prop)
34
        }
35
}