Reputation: 4636
I have One XML file which will be look like this ::
<Note>
<NoteId>13328</NoteId>
<NoteTitle>hiiiii</NoteTitle>
<NoteDescription>Hi</NoteDescription>
</Note>
I am successfully parse this kind of XML.My Problem is that when i fired the webservice and if there is no authentication from the server then the webservice response like this::
<AuthenticationError>An Active Session Already Exists For This User.</AuthenticationError>
So how can i check that root node is "Authentication Error" or "Notes". And if i get the Authentication Error tag then how can i get its node value which is "An Active Session Already Exists For This User."??
My Code for XML Parsing is this::
Element node=null;
node = (Element)result.getElementsByTagName("Notes").item(0);
websiteList = node.getElementsByTagName("Note");
for(int j=0;j<websiteList.getLength();j++)
{
Element checkNode=(Element)websiteList.item(j);
MessagesInbox msg_inbox=new MessagesInbox();
msg_inbox.note_id = getValueFromNode(checkNode,"NoteId");
msg_inbox.note_title = getValueFromNode(checkNode,"NoteTitle");
msg_inbox.note_description = getValueFromNode(checkNode,"NoteDescription");
arr_msg_inbox_list.add(msg_inbox);
}
I hope my question is clear... Please provide the solution asap. Thanks in Advance....
Upvotes: 1
Views: 2953
Reputation: 94645
You can get root node reference via calling this method - document.getDocumentElement()
.
Element root=document.getDocumentElement();
if(root.getNodeName().equals("AuthenticationError")){
//get text content
String str=root.getTextContent();
}else{
//
}
Upvotes: 1