What you learn: You will learn how to take care of a XML response. In this case a SOAP response. We will be using XPath and a technique that could be compared to a pull parser. We will use Ximpleware VTD-XML the API can be found here.

Why? What's next? In my first tutorial we looked into how to connect to icloud (SOAP + digest), this is the second step towards the cloud and all it's possibilities.

Now with these objects initiated, XML-parsed and the navigator associated with the AutoPilot class we can navigate through the XML with either the classical DOM way with selectElement and first-child, next-sibling etc, the other way is as promissed XPath with the selectXPath function. Let's look into the different ways below starting with a XPath example.

Comment: strCurrentElement equals "username" and strCurrentTextValue equals "cafe12tutorial". What we did was just to the next sibling, from <userid> to <username>.When navigating with VTDNav it's all about indexes (positions in the document), getCurrentIndex() returns where we are now, and the toString function with the index parameter works just like you expect it to. getText() will return the index of the text-element (value of a node), and run toString on that index and you will get the textual value of the text-element (if there is any, else getText() will return -1 and you'll get a IndexOutOfBoundsException if you run toString(-1)).

Now check the documentation for a full list of available navigation methods and constants like NEXT_SIBLING, FIRST_CHILD, PARENT and more in VTDNav. My recommendation is that you try to use the VTDNav class as much as possible, and the AutoPilot only when in a real complex structure or for a initial position to start navigating from, like in the above example

Now to give this tutorial some more weight I'll give you a short snippet where we select the unique key for my/your folderXML (this is your folder tree, which is the heart for your online filesystem, once you have this you can start download, creating and uploading files from or to your folder structure).

If we continue from where we left in the last tutorial we can make it like this for loging in and then fetching our folderXML (Id is found in the login response).

Comment 1: This is the login function that we created in the last tutorial with some additional rows at the end

Comment 2: The code below is the "same" as above where you can find the description of what we use it for. Note that I've added some try catch.

Comment 3: In the last tutorial I explained how the callServer function was implemented and how we build our request body. This should be pretty basic, and you should also be able to implement your own request bodies.

Below you see the request body and the response from getFolderXML (remember it won't look the exact same way when you login)