accessing XML value from web service

edited March 2014 in Programming Questions

Probaly missing something simple but, I'm working to link web service to processing on android to arduino. I'm good with all the links and pieces but I have not had luck easily getting actual values out of the xml returned to from the web service. the xml seems well formed and all, and I can get to individual attributes like 1 with getChild(), but no luck in getting to just the actual field value: 1 for example for account id.

considering an web service that returns something like the followingto and XML[]:

<categories>
<category id="1">
<categoryname>Customer Account</categoryname>
<accountid>1</accountid>
</category>
</categories>

When I run something like the following against it:

         for(int i = 0; i < categories.length; i++) {
              int id = categories[i].getInt("id");
              XML catName = categories[i].getChild("categoryname"); 
              XML actID = categories[i].getChild("accountid");

              println(id);
              println(catName);
              println(actID);

          }

I get as an example:

1
<categoryname>Customer Account</categoryname>
<accountid>1</accountid>

What xml function/syntax do I use to get just the values from the various xml tag bound values (1, Customer Account, 1) without the start and end tags so I can assign to a variable without parsing?

Help is greatly appreciated.

Answers

  • Answer ✓

    Just figured it out -

    String catName = categories[i].getChild("categoryname").getContent();

Sign In or Register to comment.