public static Xpp3Dom build(Reader reader)
        throws Exception
    {
        ArrayList arraylist;
        ArrayList arraylist1;
        MXParser mxparser;
        int i;
        Xpp3Dom xpp3dom;
        arraylist = new ArrayList();
        arraylist1 = new ArrayList();
        mxparser = new MXParser();
        mxparser.setInput(reader);
        i = mxparser.getEventType();
        xpp3dom = null;
_L2:
        Xpp3Dom xpp3dom2;
        if(i == 1)
            break; /* Loop/switch isn't completed */
        if(i == 2)
        {
            Xpp3Dom xpp3dom1 = new Xpp3Dom(mxparser.getName());
            int j = arraylist.size();
            if(j > 0)
                ((Xpp3Dom)arraylist.get(j - 1)).addChild(xpp3dom1);
            arraylist.add(xpp3dom1);
            arraylist1.add(new StringBuffer());
            int k = mxparser.getAttributeCount();
            for(int l = 0; l < k; l++)
                xpp3dom1.setAttribute(mxparser.getAttributeName(l), mxparser.getAttributeValue(l));

            xpp3dom2 = xpp3dom;
        } else
        if(i == 4)
        {
            ((StringBuffer)arraylist1.get(arraylist1.size() - 1)).append(mxparser.getText());
            xpp3dom2 = xpp3dom;
        } else
        {
            if(i != 3)
                break MISSING_BLOCK_LABEL_313;
            int i1 = arraylist.size() - 1;
            Xpp3Dom xpp3dom3 = (Xpp3Dom)arraylist.remove(i1);
            String s = arraylist1.remove(i1).toString();
            String s1;
            if(s.length() == 0)
                s1 = null;
            else
                s1 = s;
            xpp3dom3.setValue(s1);
            if(i1 != 0)
                break MISSING_BLOCK_LABEL_313;
            xpp3dom2 = xpp3dom3;
        }
_L3:
        i = mxparser.next();
        xpp3dom = xpp3dom2;
        if(true) goto _L2; else goto _L1
  public void testBuildTrimming() throws Exception {
    String domString = createDomString();

    Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);

    assertEquals("test with trimming on", "element1", dom.getChild("el1").getValue());

    dom = Xpp3DomBuilder.build(new StringReader(domString), false);

    assertEquals("test with trimming off", " element1\n ", dom.getChild("el1").getValue());
  }
  public void testEscapingInAttributes() throws IOException, XmlPullParserException {
    String s = getAttributeEncodedString();
    Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));

    assertEquals("Check attribute value", "<foo>", dom.getChild("el").getAttribute("att"));

    StringWriter w = new StringWriter();
    Xpp3DomWriter.write(w, dom);
    String newString = w.toString();
    assertEquals("Compare stringified DOMs", newString, s);
  }
  public void testEscapingInContent() throws IOException, XmlPullParserException {
    Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));

    assertEquals("Check content value", "\"text\"", dom.getChild("el").getValue());
    assertEquals("Check content value", "<b>\"text\"</b>", dom.getChild("ela").getValue());
    assertEquals("Check content value", "<b>\"text\"</b>", dom.getChild("elb").getValue());

    StringWriter w = new StringWriter();
    Xpp3DomWriter.write(w, dom);
    assertEquals("Compare stringified DOMs", getExpectedString(), w.toString());
  }
 private static Xpp3Dom createExpectedDom() {
   Xpp3Dom expectedDom = new Xpp3Dom("root");
   Xpp3Dom el1 = new Xpp3Dom("el1");
   el1.setValue("element1");
   expectedDom.addChild(el1);
   Xpp3Dom el2 = new Xpp3Dom("el2");
   el2.setAttribute("att2", "attribute2\nnextline");
   expectedDom.addChild(el2);
   Xpp3Dom el3 = new Xpp3Dom("el3");
   el3.setAttribute("att3", "attribute3");
   el3.setValue("element3");
   el2.addChild(el3);
   Xpp3Dom el4 = new Xpp3Dom("el4");
   el4.setValue("");
   expectedDom.addChild(el4);
   Xpp3Dom el5 = new Xpp3Dom("el5");
   expectedDom.addChild(el5);
   Xpp3Dom el6 = new Xpp3Dom("el6");
   el6.setAttribute("xml:space", "preserve");
   el6.setValue("  do not trim  ");
   expectedDom.addChild(el6);
   return expectedDom;
 }
  public static Xpp3Dom build(XmlPullParser parser, boolean trim)
      throws XmlPullParserException, IOException {
    List<Xpp3Dom> elements = new ArrayList<Xpp3Dom>();

    List<StringBuilder> values = new ArrayList<StringBuilder>();

    int eventType = parser.getEventType();

    boolean spacePreserve = false;

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        spacePreserve = false;

        String rawName = parser.getName();

        Xpp3Dom childConfiguration = new Xpp3Dom(rawName);

        int depth = elements.size();

        if (depth > 0) {
          Xpp3Dom parent = elements.get(depth - 1);

          parent.addChild(childConfiguration);
        }

        elements.add(childConfiguration);

        if (parser.isEmptyElementTag()) {
          values.add(null);
        } else {
          values.add(new StringBuilder());
        }

        int attributesSize = parser.getAttributeCount();

        for (int i = 0; i < attributesSize; i++) {
          String name = parser.getAttributeName(i);

          String value = parser.getAttributeValue(i);

          childConfiguration.setAttribute(name, value);

          spacePreserve = spacePreserve || ("xml:space".equals(name) && "preserve".equals(value));
        }
      } else if (eventType == XmlPullParser.TEXT) {
        int depth = values.size() - 1;

        @SuppressWarnings("MismatchedQueryAndUpdateOfStringBuilder")
        StringBuilder valueBuffer = values.get(depth);

        String text = parser.getText();

        if (trim && !spacePreserve) {
          text = text.trim();
        }

        valueBuffer.append(text);
      } else if (eventType == XmlPullParser.END_TAG) {
        int depth = elements.size() - 1;

        Xpp3Dom finishedConfiguration = elements.remove(depth);

        /* this Object could be null if it is a singleton tag */
        Object accumulatedValue = values.remove(depth);

        if (finishedConfiguration.getChildCount() == 0) {
          if (accumulatedValue == null) {
            finishedConfiguration.setValue(null);
          } else {
            finishedConfiguration.setValue(accumulatedValue.toString());
          }
        }

        if (depth == 0) {
          return finishedConfiguration;
        }
      }

      eventType = parser.next();
    }

    throw new IllegalStateException("End of document found before returning to 0 depth");
  }