+1  A: 

You could take the content of param1, like this:

public String getParam1(Document d) {
        if (d.getDocumentElement().getTagName().equals("AmigoRequest")) {
            NodeList results = d.getElementsByTagName("Param1");
            // Messagetype depends on what message we are reading.           
            if (results.getLength() > 0 && results != null) {                

                // String extractHTMLTags(String s) is a function that you have 
                // to implement in a way that will extract all the HTML tags inside a string.
                return extractHTMLTags(results.item(0).getTextContent());
            }
        }
        return "";
    }

All you have to do is to implement a function:

String extractHTMLTags(String s)

that will remove all HTML tag occurrences from a string. For that you can take a look at this post: http://stackoverflow.com/questions/240546/removing-html-from-a-java-string

Alex
Too bad Android doesn't supports the getTextContent function. Android is using an old dom parser. But i know where too look now. Still havn't found a solution for the topic, but I've edited my topic title.
Antek
If `getTextContent` were available on the platform, it should be sufficient to call it without wrapping an `extractHTMLTags` call around it. `getTextContent` strips any XML markup from the string that's returned (more accurately, it gets its value by concatenating all of the text strings inside the nested elements, while leaving the element tags behind.) Of course, this does assume that the HTML content is well-formed XML. But if it isn't, you probably won't even get as far as this in the XML parsing.
Dan Breslau
Oh, I've never used android and I didn't know about its DOM parser! I thought it was using the latest version. Sorry about that!
Alex
No Alex, don't be sorry :) You helped me in a right direction, i found some usefull information about Androids dom parser. Seems it can only extract Textnodes. I'm currently looking into all other comments.
Antek
A: 

EDIT: I just saw your comment above about getTextContent() not being supported on Android. I'm going to leave this answer up in case it's useful to someone who's on a different platform.

If your DOM API supports it, you can call getTextContent(), as follows:

public String getParam1(Document d) {
        if (d.getDocumentElement().getTagName().equals("AmigoRequest")) {
            NodeList results = d.getElementsByTagName("Param1");
            // Messagetype depends on what message we are reading.           
            if (results != null) {                
                return results.getTextContent();
            }
        }
        return "";
    }

However, getTextContent() is a DOM Level 3 API call; not all parsers are guaranteed to support it. Xerces-J does.

By the way, in your original example, your check for null is in the wrong place; it should be:

        if (results != null && results.getLength() > 0) {                

Otherwise, you'd get a NPE if results really does come back as null.

Dan Breslau
A: 

Since getTextContent() isn't available to you, another option would be to write it -- it isn't hard. In fact, if you're writing this solely for your own use -- or your employer doesn't have overly strict rules about open source -- you could look at Apache's implementation as a starting point; lines 610-646 seem to contain most of what you need. (Please be respectful of Apache's copyright and license.)

Otherwise, some rough pseudocode for the method would be:

String getTextContent(Node node) {
    if (node has no children) 
        return "";

    if (node has 1 child)
        return getTextContent(node.getFirstChild());

    return getTextContent(new StringBuffer()).toString();
}

StringBuffer getTextContent(Node node, StringBuffer sb) {
    for each child of node {
        if (child is a text node) sb.append(child's text)
        else getTextContent(child, sb);
    }
    return sb;
}
Dan Breslau
A: 

Well i was almost there with the code...

public String getParam1(Document d) {
    if (d.getDocumentElement().getTagName().equals("AmigoRequest")) {
        NodeList results = d.getElementsByTagName("Param1");
        // Messagetype depends on what message we are reading.           
        if (results.getLength() > 0 && results != null) {                
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db;
            Element node = (Element) results.item(0); // get the value of Param1
            Document doc2 = null;
            try {

                db = dbf.newDocumentBuilder();
                doc2 = db.newDocument(); //create new document
                doc2.appendChild(doc2.importNode(node, true)); //import the <html>...</html> result in doc2

            } catch (ParserConfigurationException e) {
                // TODO Auto-generated catch block
                Log.d(TAG, " Exception ", e);
            } catch (DOMException e) {
                // TODO: handle exception
                Log.d(TAG, " Exception ", e);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();               }              


            return doc2. .....// All I'm missing is something to convert a Document to a string.
        }
    }
    return "";

}

Like explained in the comment of my code. All I am missing is to make a String out of a Document. You can't use the Transform class in Android... doc2.toString() will give you a serialization of the object..

But my next step is write my own parser if this doesnt work out ;)

Not the best code but a temponary solution.

public String getParam1(String b) {
        return b
                .substring(b.indexOf("<Param1>") + "<Param1>".length(), b.indexOf("</Param1>"));
    }

Where String b is the XML document string.

Antek