File: strip-package-xml.php

package info (click to toggle)
php-horde-ansel 3.0.10%2Bdebian1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,020 kB
  • sloc: php: 15,720; xml: 1,994; javascript: 1,784; makefile: 37; sh: 3
file content (31 lines) | stat: -rw-r--r-- 853 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/php
<?php
/**
 * This script removes references to files from package.xml
 */

function usage() {
  global $argv;
  echo "Usage:\n";
  echo "  php $argv[0] <package.xml> <filename1> [<filename2> [...]]\n";
  echo "\n";
  echo "  Remove references to <filename1>, <filename2>, ... from package.xml\n";
}

if (($argc < 3) || ($argv[1] == '-h') || ($argv[1] == '--help')) {
  usage();
  exit(1);
}

$args = $argv;
array_shift($args); // script name
$filePath = array_shift($args); // package.xml path
$domDocument = DOMDocument::load($filePath);
$domXPath = new DOMXPath($domDocument);
foreach($args as $nameToRemove) {
  $elementsToRemove = $domXPath->query("//*[@name='${nameToRemove}']");
  foreach($elementsToRemove as $elementToRemove) {
    $elementToRemove->parentNode->removeChild($elementToRemove);
  }
}
$domDocument->save($filePath);