JuanLu's blog


Showing data contained into a XML Element

Posted in proyectos by JuanLu on the 20/11/2008
Tags: , ,

The other day I had an small issue trying to show the data contained into a DOM element, due that I was targeting a null value, because of the way that Node and Element are managed.

Let’s go to the beginning. What I had was a hole Document store in a variable, from that document I got a NodeList of Elements (in this case as it is a NodeList they are Node) that have this aspect, a normal element with data inside:

<c:customer xmlns:c=”http://engage.bt.com/customer”>
<c:id>1</c:id>
<c:name>John</c:name>
<c:lastname>Smith</c:lastname>
<c:department>Finance</c:department>
</c:customer>

I wanted to take the values that the child within this Node have, but they way that the type Node is manages doesn’t allow you to get the children of this element and get the node value that is inside a child such as <c:id>, for instance, because you end up getting the null point that I commented as my problem.

So here it comes the trick, what you have to do is cast the Node (the one shown above) into an Element.

Element customerElement = (Element)customersList.item(i);

Once you have this done, you have to get the Elements within the father by using the function getElementsByTagName(String tagName) , where you will get again a NodeList of elements with the tag name that you say. So now we only have this: <c:id>1</c:id>. So now as a list that it is we should point in the first item, so item(0). Once in this item the value is treated as a child so we need to get that child out by using the function getFirstChild(). Now we reach the point where the value is within our node, so we only need to getNodeValue(), which return a String, so we have to be careful and parse the real Type that we need.

Ok this is been specify step by step, but to make it clear what I used in the end is a function in which you give an Element (<c:customer> in this case) and a tagName (any tag of the children) and gives you the value back. The function is not other than this:

private String getData(Element customer, String tagName){
return customer.getElementsByTagName(tagName).item(0).getFirstChild().getNodeValue();
}

Therefore using this call you get the value for free

String customerData = getData(customer,”c:name”);

Finally updating the iPhone

Posted in iPhone by JuanLu on the 18/11/2008
Tags: ,

Yesterday, after a long time since the firmware 2.1 for the iPhone I have updated it yesterday.

First of all I made a security copy to recover everything after the update, otherwise it is a mess to have to put all the contacts, notes and stuff again from the beginning. You loose data yes,  but the important one is there ready for you, that in the end it is what it counts, isn’t it? ;)

So, it took me a while since I got it. I was using my new macbook (the white one), PwnageTool and QuickPwn for 2.1 Firmware to create the new hack firmware and iTunes 8 to install the software in the iPhone once the customize one is done. At the beginning I didn’t know  well how to use Pwnage so I choose the “easy mode” on it and I created a new customize version. Following the instructions that this tool told me I put my phone into DFU mode, I did it and I plugged it to the laptop. Then the way was suppose to be easy, just let iTunes restore the phone and that’s all, but NO. Murphy’s law appeared and I got an error 21, that I still don’t know what is it about, but many people has the same problem whet they update the firmware. So I tried again doing the same process up to the point that it happened to me a few times and I became to be a bit nervous. Once reached this point I decided to use QuickPwn a tool of the same team that does everything directly for you, so I followed the instructions I saw on the screen and continue with the procedure. Well this worked!! But something was wrong again because my phone didn’t catch network :s (I have to say that it was more than 2:00 am) so finally I decided to have it done unless it would cost me the hole night. I tried again with Pwnage and one of the customize software that I had already build from my other attempts and this time, once passed 2:30 am my phone was finally unlocked, jailbreak, up and running with the new 2.1 software. Software which I think is much better than the 1.1.4 because it is faster, you have app store, and a terminal “for free”, so you can play more with the phone when you are on a network :)

Once I did it I recover the info I backed up at the beginning and I started playing with it. Yesterday I didn’t do much because I was tired , but soon I’ll say how is this new software from my point of view ;)