Skip to content
May 18, 2009 / ffstefan

simpleXML strip all / unknown NameSpaces

Problem: you dont know the name space in a XML document. If you dont need it and want to work with PHP SimpleXML, simply strip it (fast):

$data = $SomeInputXMLString;
$xml = simplexml_load_string($data);
$ns = $xml->getNameSpaces();
$defaultNamespace=”;
foreach ($ns AS $key => $val){
     if ($key==’xsi’) continue;
     $xml->registerXPathNamespace($key, $val);
     $defaultNamespace=$val;
}
 $cleanUp = $xml->children($defaultNamespace);
 

$data = $this->framework->filesystem->getFileContent($filename);
$xml = simplexml_load_string($data);
$ns = $xml->getNameSpaces();
$defaultNamespace=”;
foreach ($ns AS $key => $val){
if ($key==’xsi’) continue;
$xml->registerXPathNamespace($key, $val);
$defaultNamespace=$val;
}
$cleanUp = $xml->children($defaultNamespace); $data = $this->framework->filesystem->getFileContent($filename);
$xml = simplexml_load_string($data);
$ns = $xml->getNameSpaces();
$defaultNamespace=”;
foreach ($ns AS $key => $val){
if ($key==’xsi’) continue;
$xml->registerXPathNamespace($key, $val);
$defaultNamespace=$val;
}
$cleanUp = $xml->children($defaultNamespace) $data = $this->framework->filesystem->getFileContent($filename);
$xml = simplexml_load_string($data);
$ns = $xml->getNameSpaces();
$defaultNamespace=”;
foreach ($ns AS $key => $val){
if ($key==’xsi’) continue;
$xml->registerXPathNamespace($key, $val);
$defaultNamespace=$val;
}
$cleanUp = $xml->children($defaultNamespace);sdf
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: