title: Parse XML file in Pig using UDF
body: <p>I want to parse an XML file using Pig . Please find below the XML </p>
  
  <pre><code>&lt;catalog&gt;
    &lt;book id="bk101"&gt;
      &lt;author&gt;Gambardella, Matthew&lt;/author&gt;
      &lt;title&gt;XML Developer's Guide&lt;/title&gt;
      &lt;genre&gt;Computer&lt;/genre&gt;
      &lt;price&gt;
         &lt;amount&gt;25&lt;/amount&gt;
         &lt;tax&gt;12&lt;/tax&gt;
         &lt;total&gt;37&lt;/total&gt;
      &lt;/price&gt;
      &lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;
      &lt;description&gt;An in-depth look at creating applications with XML&lt;/description&gt;
    &lt;/book&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>I am currently using XMLLoader to load the XML file and using regex to parse the XML</p>
  
  <p>Code :</p>
  
  <pre><code>REGISTER piggybank.jar
  
  A=LOAD '/users/books.xml' using org.apache.pig.piggybank.storage.XMLLoader
  ('book') as (x:chararray);
  
  B=FOREACH A GENERATE(REGEX_EXTRACT_ALL(x,'&lt;book.*?id="([^&gt;]*?"&gt;.*?&lt;author&gt;([^&gt;]*?)&lt;/author&gt;.*?&lt;/book&gt;'));
  
  dump B;
  </code></pre>
  
  <p>I want to understand if there is any other way to parse XML - may be using a UDF. Is there any UDF available to parse XML or how can i create a UDF to serve my purpose. I am using Pig version 0.12 and XPath is not working in this version.</p>
  
  <p>Thanks in advance</p>