Android : Request XML to the web Server And Parse The Content as String[]


<content>
<title>xml is  bla bla</title>
<body>
The function of the markup in an XML document
</body>
</content>

<content>
<title>all definisions are bla bla</title>
<body>
Definition: The XML document type declaration contains or points to markup declarations that provide a grammar for a class of documents. This grammar is known as a document type definition.
</body>
</content>
<content>
<title>bla vla 1</title>
<body>
Definition: The XML document type declaration contains or points to markup declarations that provide a grammar for a class of documents. This grammar is known as a document type definition
</body>
</content>
<content>
<title>bla bla2</title>
<body>
Definition: The XML document type declaration contains or points to markup declarations that provide a grammar for a class of documents. This grammar is know.
</body>
</content>

code:

URL url = new URL(“http://192.168.0.124/notepad/getnotes.xml&#8221;);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();

NodeList titleNode = doc.getElementsByTagName(“title”);
NodeList bodyNode = doc.getElementsByTagName(“body”);

for (int i = 0; i < titleNode.getLength(); i++) {

Node nodeTitle = titleNode.item(i);
Node nodeBody = bodyNode.item(i);
//this.showDialogMessage(“response”, node.getTextContent() );
//this.showDialogMessage(“response”, node.getTextContent() );
//this.showDialogMessage(“response”, nodeBody.getTextContent() );
notesTitle.add( nodeTitle.getTextContent() );
}

Object[] objs = notesTitle.toArray();
String[] strings = new String[objs.length];
for(int i=0;i<objs.length;i++)  {
strings[i] = (String)objs[i];
}
return strings;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s