XmlPullParser to DOM (so I can use xpath)

Hello,

I am trying to implement a PacketExtensionProvider and I’d like to create an object (DOM?) inside so that I may use xpath. I tried this :

public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
String version = parser.getAttributeValue("", “version”);
int eventType = parser.nextTag();
if(eventType == XmlPullParser.START_TAG) {

        if(parser.getName().equals("payload")) {

           String payloadType = parser.getAttributeValue("", "type");
           DOM2XmlPullBuilder builder = new DOM2XmlPullBuilder();
           DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
           DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
           Document doc = docBuilder.newDocument();
           Element el = builder.parse(parser, doc);
           System.out.println(el);

        }

     }

 }

And it doesn’t work at all, I get null pointer exceptions. I think I have it all wrong anyway’s, my question is has anyone done this before and/or does anyone know how to do this? I’d like to have an object that contains the payload node and all it’s children (with their attributes too) that allows me to use xpath on it.

Thank you for your help,

Gabriel