@Override
    public XHTMLExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException {
        XHTMLExtension xhtmlExtension = new XHTMLExtension();

        while (true) {
            XmlPullParser.Event eventType = parser.getEventType();
            if (eventType == XmlPullParser.Event.START_ELEMENT) {
                String name = parser.getName();
                if (name.equals(Message.BODY)) {
                    xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
                }
            } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
                if (parser.getDepth() == initialDepth) {
                    return xhtmlExtension;
                }
            }
            parser.next();
        }
    }
@Test
    public void parsesWell() throws IOException, XmlPullParserException {
        InputStream inputStream = getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME);
        XmlPullParser parser = PacketParserUtils.getParserFor(inputStream);

        XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
        ExtensionElement extension = provider.parse(parser, parser.getDepth(), null);

        assertThat(extension, instanceOf(XHTMLExtension.class));
        XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;

        assertThat(sampleXhtml(), equalsCharSequence(attachmentsInfo.getBodies().get(0)));
    }