 <p>The use of <code>$xml</code> variable looks like it is loaded with SimpleXML extension. Suppose it is initialized like this:</p> <pre><code>$xml = simplexml_load_file('some-file.xml'); </code></pre> <p>Then you just fetch attributes with <a href="http://php.net/manual/en/simplexmlelement.attributes.php" rel="nofollow"><code>attributes()</code></a> and check if the attribute is in the returned array:</p> <pre><code>foreach ($xml as $idof) { $attr = $idof-&gt;attributes(); if ($attr &amp;&amp; $attr['mlssta'] != 6) { // remove it here } } </code></pre>