Extract attribute value in XML using xpath in PIG

I have the following input XML

<Type>  
    <Source>        
        <TimeStamp>2016-02-19T12:27:06.387Z</TimeStamp>
        <IPAddress IPVersion="IPv4">x.xx.xxx.xxx</IPAddress>
        <Port>64435</Port>
        <DNS_Name>x.xx.xxx.xxx.range9-27.abc.com</DNS_Name>
    </Source>
 </Type>

I am trying to get all the values ​​from the above tags using the code below.

REGISTER piggybank-0.15.0.jar
            DEFINE XPath org.apache.pig.piggybank.evaluation.xml.XPath();

        A =  LOAD 'test.xml' using org.apache.pig.piggybank.storage.XMLLoader('Type') as (x:chararray);
        B = FOREACH A GENERATE 
                               XPath(x, 'Source/TimeStamp')
                               ,XPath(x, 'Source/IPAddress')
                               ,XPath(x, 'Source/IPAddress/@IPVersion')
                               ,XPath(x, 'Source/Port')
                               ,XPath(x, 'Source/DNS_Name');

When I reset B, I get the following output where the IPVersion value is missing.

(2016-02-19T12:27:06.387Z,x.xx.xxx.xxx,,64435,x.xx.xxx.xxx.range9-27.abc.com) 

Can anyone help me solve this problem?

+4
source share
1 answer

There are 2 XPath class errors in piggybank :

. XPathAll

+3

All Articles