Skip to content

Commit d012262

Browse files
committed
Refactored the way to remove namespaces
1 parent 8e97350 commit d012262

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Sdmx/api/parser/ParserUtils.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ class ParserUtils
1111
*/
1212
public static function removeNamespaces($data)
1313
{
14-
$dataWoNs = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $data);
15-
$dataWoNs = preg_replace('/<!\[CDATA\[(.*)\]\]>/s', '$1', $dataWoNs);
16-
$dataWoNs = preg_replace('/<!--(.*)-->/s', '$1', $dataWoNs);
17-
$dataWoNs = preg_replace('/[a-zA-Z]+:([a-zA-Z]+[=>])/', '$1', $dataWoNs);
18-
$dataWoNs = preg_replace('/(<\/*)[^>:]+:/', '$1', $dataWoNs);
14+
$data = str_replace(PHP_EOL, '', $data);
15+
$dataWoNs = preg_replace('/xmlns[^=]*="[^"]*"/i', '', $data); //Remove ns declarations.
16+
//$dataWoNs = preg_replace('/<!\[CDATA\[(.*)\]\]>/', '$1', $dataWoNs); //Replace CDATA by content.
17+
//$dataWoNs = preg_replace('/<!--(.*)-->/', '', $dataWoNs); //Remove comments
18+
$dataWoNs = preg_replace('/[a-z0-9]+:([a-z0-9]+=)/i', '$1', $dataWoNs); //Remove ns in attributes
19+
$dataWoNs = preg_replace('/<[a-z0-9]+:([a-z0-9]+)/i', '<$1', $dataWoNs); //Remove ns in opening tags
20+
$dataWoNs = preg_replace('/<\/[a-z0-9]+:([a-z0-9]+)/i', '</$1', $dataWoNs); //Remove ns in closing tags
1921

2022
return $dataWoNs;
2123
}

0 commit comments

Comments
 (0)