title: PIG - retrieve data from XML using XPATH
body: <p>I <strong>have n number</strong> of these type of xml files.</p>
  
  <pre><code>&lt;students roll_no=1&gt;
      &lt;name&gt;abc&lt;/name&gt;
      &lt;gender&gt;m&lt;/gender&gt;
      &lt;maxmarks&gt;
          &lt;marks&gt;
              &lt;year&gt;2014&lt;/year&gt;
              &lt;maths&gt;100&lt;/maths&gt;
              &lt;english&gt;100&lt;/english&gt;
              &lt;spanish&gt;100&lt;/spanish&gt;
          &lt;marks&gt;
          &lt;marks&gt;
              &lt;year&gt;2015&lt;/year&gt;
              &lt;maths&gt;110&lt;/maths&gt;
              &lt;english&gt;110&lt;/english&gt;
              &lt;spanish&gt;110&lt;/spanish&gt;
          &lt;marks&gt;
      &lt;/maxmarks&gt;
      &lt;marksobt&gt;
          &lt;marks&gt;
              &lt;year&gt;2014&lt;/year&gt;
              &lt;maths&gt;90&lt;/maths&gt;
              &lt;english&gt;95&lt;/english&gt;
              &lt;spanish&gt;82&lt;/spanish&gt;
          &lt;marks&gt;
          &lt;marks&gt;
              &lt;year&gt;2015&lt;/year&gt;
              &lt;maths&gt;94&lt;/maths&gt;
              &lt;english&gt;98&lt;/english&gt;
              &lt;spanish&gt;02&lt;/spanish&gt;
          &lt;marks&gt;
      &lt;/marksobt&gt;
  &lt;/Students&gt;
  </code></pre>
  
  <p>I need output like </p>
  
  <pre><code>roll_no name    gender  year    eng_max_marks   maths_max_marks spanish_max_marks
  1       abc     m       2014    100                 100          100
  1       abc     m       2015    110                 110          110
  </code></pre>
  
  <p>I am able to retrieve marks row wise in single statement but not able to extract roll_no and name with this.</p>
  
  <pre><code>A =  LOAD 'student.xml' using org.apache.pig.piggybank.storage.XMLLoader('marks') as (x:chararray);
  
  B = FOREACH A GENERATE XPath(x, 'marks/year'), XPath(x, 'marks/english'), XPath(x, 'marks/math'), XPath(x, 'marks/spanish');
  </code></pre>
  
  <p>This return </p>
  
  <pre><code>year    eng_max_marks   maths_max_marks spanish_max_marks
  2014    100              100             100
  2015    110              110             110
  </code></pre>
  
  <p>I can extract both the chunks but not getting how to join other fields. I can't use across join because I have n number of other files. </p>
  
  <p>Let's forger attribute name (roll_no) for now. How can I extract the rest of nodes</p>
  
  <pre><code>name    gender  year    eng_max_marks   maths_max_marks spanish_max_marks
  abc      m     2014      100             100             100
  abc      m     2015      110             110             110
  </code></pre>
  
  <p>I don't want to use marks(1)/english approach because this nodes can also vary and don't want to adopt any dirty approach.</p>
  
  <p>Any pointers????</p>