@Override
    public ContentElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
            throws XmlPullParserException, IOException, ParseException, SmackParsingException {
        ContentElement.Builder builder = ContentElement.builder();

        while (true) {
            XmlPullParser.Event tag = parser.next();
            if (tag == XmlPullParser.Event.START_ELEMENT) {
                String name = parser.getName();
                switch (name) {
                    case ToAffixElement.ELEMENT:
                        parseToAffix(parser, builder);
                        break;

                    case FromAffixElement.ELEMENT:
                        parseFromAffix(parser, builder);
                        break;

                    case TimestampAffixElement.ELEMENT:
                        parseTimestampAffix(parser, builder);
                        break;

                    case RandomPaddingAffixElement.ELEMENT:
                        parseRPadAffix(parser, builder);
                        break;

                    case PayloadElement.ELEMENT:
                        parsePayload(parser, xmlEnvironment, builder);
                        break;

                    default:
                        parseCustomAffix(parser, xmlEnvironment, builder);
                        break;
                }
            } else if (tag == XmlPullParser.Event.END_ELEMENT) {
                if (parser.getDepth() == initialDepth) {
                    break;
                }
            }
        }
        return builder.build();
    }
@Test
    public void testParsing() throws XmlPullParserException, IOException, SmackParsingException, ParseException {
        String xml = "" +
                "<content xmlns='urn:xmpp:sce:0'>\n" +
                "  <payload>\n" +
                "    <body xmlns='jabber:client'>Have you seen that new movie?</body>\n" +
                "    <x xmlns='jabber:x:oob'>\n" +
                "      <url>https://en.wikipedia.org/wiki/Fight_Club#Plot</url>\n" +
                "    </x>\n" +
                "  </payload>\n" +
                "  <from jid='ladymacbeth@shakespear.lit/castle'/>\n" +
                "  <to jid='doctor@shakespeare.lit/pda'/>\n" +
                "  <time stamp='1993-10-12T03:13:10.000+00:00'/>\n" +
                "  <rpad>A98D7KJF1ASDVG232sdff341</rpad>\n" +
                "</content>";

        ContentElementProvider provider = new ContentElementProvider();
        ContentElement contentElement = provider.parse(TestUtils.getParser(xml));

        assertNotNull(contentElement);

        assertEquals(4, contentElement.getAffixElements().size());
        assertTrue(contentElement.getAffixElements().contains(
                new FromAffixElement(JidCreate.from("ladymacbeth@shakespear.lit/castle"))));
        assertTrue(contentElement.getAffixElements().contains(
                new ToAffixElement(JidCreate.from("doctor@shakespeare.lit/pda"))));
        assertTrue(contentElement.getAffixElements().contains(
                new TimestampAffixElement(ParserUtils.getDateFromXep82String("1993-10-12T03:13:10.000+00:00"))));
        assertTrue(contentElement.getAffixElements().contains(
                new RandomPaddingAffixElement("A98D7KJF1ASDVG232sdff341")));

        assertEquals(2, contentElement.getPayload().getItems().size());

        assertTrue(contentElement.getPayload().getItems().get(0) instanceof Message.Body);
        Message.Body body = (Message.Body) contentElement.getPayload().getItems().get(0);
        assertEquals("Have you seen that new movie?", body.getMessage());

        StandardExtensionElement oob = (StandardExtensionElement) contentElement.getPayload().getItems().get(1);
        assertEquals("x", oob.getElementName());
        assertEquals("jabber:x:oob", oob.getNamespace());
        assertEquals("https://en.wikipedia.org/wiki/Fight_Club#Plot", oob.getFirstElement("url").getText());
    }