title: JSON/XML parsen in java
body: <p>So I can get two possible outputs out of an API, I can choose what i want, the thing is i need to parse it in my java code and get the Value at the gm tag, or throw an Exception if there is no gm tag, and get one value out of it, the librarys I'm using are: org.json,org.apache.commons.configuration, i can use what i want as long as it can be injected with Maven. Throwing the Exception etc. is simple, accessing the value on the other hand gets me, if there is no simple solution i'll just write a while loop that is searching for the tag</p>
  
  <p>The XML-String looks like this:</p>
  
  <pre><code>&lt;report sr="28" groups="All groups" subset="All foods" end="0" start="0" total="0"&gt;
      &lt;foods&gt;
          &lt;food ndbno="45149194" name="AHOLD, DIET GINGER BEER, UPC: 688267176883" weight="355.0" measure="1.0 BOTTLE"&gt;
              &lt;nutrients&gt;
                  &lt;nutrient nutrient_id="208" nutrient="Energy" unit="kcal" value="0" gm="0.0"/&gt;
              &lt;/nutrients&gt;
          &lt;/food&gt;
      &lt;/foods&gt;
  &lt;/report&gt;
  </code></pre>
  
  <p>The JSON-String looks like this:</p>
  
  <pre><code>{
      "report": {
          "sr": "28",
          "groups": "All groups",
          "subset": "All foods",
          "end": 0,
          "start": 0,
          "total": 0,
          "foods": [
              {
                  "ndbno": "45149194",
                  "name": "AHOLD, DIET GINGER BEER, UPC: 688267176883",
                  "weight": 355.0,
                  "measure": "1.0 BOTTLE",
                  "nutrients": [
                      {
                          "nutrient_id": "208",
                          "nutrient": "Energy",
                          "unit": "kcal",
                          "value": "0",
                          "gm": 0.0
                      }
                  ]
              }
          ]
      }
  }
  </code></pre>
  
  <p>I will use whatever is more simple,I would also be happy if some1 can point out an alternativ library because org.json seems overly complicated.</p>
  
  <p>I just can't wrap my head around it, i need to access the "gm" value, or throw an Exception if there is no such value.</p>