title: Powershell - compare parts of two large XML files
body: <p>I have two large (> 100MB,several million lines each) XML files that are structured as follows.  </p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;index&gt;
      &lt;doc id='0'&gt;
          &lt;field name='PART' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;12345-678&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='DESCRIPTION' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;Part XYX123 Description&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='QTY' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;18&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='VENDOR' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;ACME&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='MFG' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;&lt;/val&gt;
          &lt;/field&gt;
      &lt;/doc&gt;
      &lt;doc id='1'&gt;
          &lt;field name='PART' norm='124' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;ABCD-1234&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='DESCRIPTION' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;PART ABCD Description&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='QTY' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;4&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='VENDOR' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;&lt;/val&gt;
          &lt;/field&gt;
          &lt;field name='MFG' norm='-1' flags='Idfp--S--Ni08--------'&gt;
              &lt;val&gt;&lt;/val&gt;
          &lt;/field&gt;
      &lt;/doc&gt;
  &lt;/index&gt;
  </code></pre>
  
  <p>I need to find items that are in one but not the other, and vice-versa.  Initially, I only want to compare the attribute <code>PART</code> value, but would like to also compare other values (Description, etc).  </p>
  
  <p>I want to determine if what's in xmlfile1:</p>
  
  <pre><code>index/doc/field name=part/val - 12345-678
  </code></pre>
  
  <p>is also in xmlfile2.  If not, write it out to a text/csv file.</p>
  
  <p>I've tried using <code>Compare-Object</code> &amp; <code>Get-Content</code>, but one of the issues that I've encountered are the other attributes that are in each XML file.  Both XML Files may have </p>
  
  <pre><code>index/doc/field name=part/val - 12345-678
  </code></pre>
  
  <p>but the difference is that xmlfile1 may have different values for the norm &amp; flags attributes than xmlfile2.  Which makes using <code>Compare-Object</code> &amp; <code>Get-Content</code> flag everything.</p>
  
  <p>Using Powershell, how would you make a compare ignore the "noise" attributes, but match on the <code>&lt;value&gt;</code> only for the <code>PART</code> attribute?</p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>To clarify - the second XML file would be nearly identical to the one shown. However - what could be different would be the <code>&lt;doc id='0'&gt;</code> in either XML, the <code>&lt;field name='PART'</code>  would be the same, but the other attributes <code>norm='-1'</code> and <code>flags='Idfp--S--Ni08--------'&gt;</code> could be different in each.  I would want to find the PART attribute, ignore the rest of the attributes in <code>field</code>, and determine if the contents in <code>&lt;val&gt;</code> exist in the second XML file.</p>