title: regex to extract data from xml nodes in php
body: <p>Here is the XML</p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;us:ItemMaster&gt;
       &lt;us:ItemMasterHeader&gt;
          &lt;oa:ItemID agencyRole="Product_Number"&gt;
             &lt;oa:ID&gt;9227950&lt;/oa:ID&gt;
          &lt;/oa:ItemID&gt;
          &lt;oa:ItemID agencyRole="Prefix_Number"&gt;
             &lt;oa:ID&gt;AAG&lt;/oa:ID&gt;
          &lt;/oa:ItemID&gt;
          &lt;oa:ItemID agencyRole="Stock_Number_Butted"&gt;
             &lt;oa:ID&gt;5035&lt;/oa:ID&gt;
          &lt;/oa:ItemID&gt;
          &lt;oa:ItemID agencyRole="Manufacturer_Sku_Number"&gt;
             &lt;oa:ID&gt;5035&lt;/oa:ID&gt;
          &lt;/oa:ItemID&gt;
       &lt;/us:ItemMasterHeader&gt;
  &lt;/us:ItemMaster&gt;
  </code></pre>
  
  <p>I want to extract the <strong>Product_Number, Prefix_Number, Stock_Number_Butted and Manufacturer_Sku_Number</strong>.</p>
  
  <p>Can you advice how to do it using regex in php?</p>
  
  <p>I don't want to use xml parser for this, that is getting very lengthy, as i have so many large xml files to process.</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <h2><strong>Update:</strong></h2>
  
  <p><strong>For those who are seeking the same</strong>
  Found <strong><a href="http://php.net/manual/en/simplexmlelement.xpath.php" rel="nofollow">xpath</a></strong> is the best way to proceed and i found this link very helpful.
  Here is the code:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  echo "&lt;pre&gt;";
  $info = array();
  $xmlStr = file_get_contents("http://officedealersolution.highviews.co.cc/sftp/ecdb.individual_items/AAG5035.xml");
  $xml = new SimpleXMLElement($xmlStr); 
  $res = $xml-&gt;xpath("//us:DataArea/us:ItemMaster/us:ItemMasterHeader/oa:ItemID[@agencyRole=\"Product_Number\"]/oa:ID"); 
  $info['Product_Number'] = $res[0];
  $res = $xml-&gt;xpath("//us:DataArea/us:ItemMaster/us:ItemMasterHeader/oa:ItemID[@agencyRole=\"Prefix_Number\"]/oa:ID"); 
  $info['Prefix_Number'] = $res[0];
  $res = $xml-&gt;xpath("//us:DataArea/us:ItemMaster/us:ItemMasterHeader/oa:ItemID[@agencyRole=\"Stock_Number_Butted\"]/oa:ID"); 
  $info['Stock_Number_Butted'] = $res[0];
  $res = $xml-&gt;xpath("//us:DataArea/us:ItemMaster/us:ItemMasterHeader/oa:ItemID[@agencyRole=\"Manufacturer_Sku_Number\"]/oa:ID"); 
  $info['Manufacturer_Sku_Number'] = $res[0];
  print_r($info);
  echo "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>Array
  (
      [Product_Number] =&gt; SimpleXMLElement Object
          (
              [0] =&gt; 9227950
          )
  
      [Prefix_Number] =&gt; SimpleXMLElement Object
          (
              [0] =&gt; AAG
          )
  
      [Stock_Number_Butted] =&gt; SimpleXMLElement Object
          (
              [0] =&gt; 5035
          )
  
      [Manufacturer_Sku_Number] =&gt; SimpleXMLElement Object
          (
              [0] =&gt; 5035
          )
  
  )
  </code></pre>
  
  <p>Here is a very good xpath tutorial by w3schools <strong><a href="http://www.w3schools.com/xpath/xpath_syntax.asp" rel="nofollow">http://www.w3schools.com/xpath/xpath_syntax.asp</a></strong></p>