-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml2txt.php
More file actions
executable file
·36 lines (27 loc) · 905 Bytes
/
xml2txt.php
File metadata and controls
executable file
·36 lines (27 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
//transforme les xml en txt en ne gardant que les morceaux en alexandrins
$files = glob($argv[1]);
print_r($files);
foreach ($files as $file) {
$file_name = basename($file, ".xml");
//toison, andromede
$dom = new DOMDocument();
$dom->load($file);
$xp = new DOMXPath($dom);
$xp->registerNamespace("tei", "http://www.tei-c.org/ns/1.0");
$lines = $xp->evaluate("//tei:body//tei:sp[not(ancestor::tei:spGrp)]/tei:l");
//stances
//parties chantées
//concat l@part
$string = "";
foreach ($lines as $line) {
if ($line->getAttribute("part") == "I" or $line->getAttribute("part") == "M") {
$string.= $line->textContent." ";
} else {
$string.= $line->textContent . "\n";
}
}
$string = trim($string)." ";
file_put_contents("../tcp5t/" . $file_name . ".txt", $string);
}
?>