C# code to read data from this XML file

I am working on webservice project. When I pass an XML to webservice, it will return back Success OR Failure XML. I need to read the response XML and need to identity whether it is success or failure.

Requirements:-
If it is Success, need to read the value of 'ProjectID' from the response XML.
If it is failure, need to read the 'Error' message text

(Attached two XML files - response_failure.XML & response_success.XML)
response-success.xml
response-failure.xml

I know, we can use XmlDocument, XmlElement, XmlNode for this purpose in C#. But not clear about that. Also i have only less time to finish this project.

Could you please assist me by providing the C# code to read the response XML as mentioned above.

Highly appreciates the help that you could provide me.

Thanks
Raj
LVL 23
Rajkumar GsSoftware EngineerAsked:
Who is Participating?
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
//failure-success.xml
            XmlNodeList list = xmldoc.SelectNodes("//informationStatus/*");
            string errMessage = list.Item(1).InnerText;

//response-success.xml
            XmlNodeList list = xmldoc.SelectNodes("//createUser/*");
            string projectID = list.Item(1).InnerText;
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
use the following code to load the xml into XmlDocument:

XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(@"<xml_file>");
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Thanks sedqwick for your help! That worked.

To identity whether the XML returned is Success or Failure, we need first to read the value status="success" / status="fail"

How to read it ?

Thanks
Raj
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
here:

XmlNodeList list = xmldoc.SelectNodes("//informationStatus/@status");
            string status = list.Item(1).InnerText;
0
 
Meir RivkinFull stack Software EngineerCommented:
@RajkumarGS

you could simply accept one of my comments as a solution instead of splitting... :-)
10x for the points anyway
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
As all of them are the answers, i tried to split points :)

I have already requested for moderator's attention. since i think it is not required to wait for objection as there is only one expert attending this question.
http://www.experts-exchange.com/Community_Support/General/Q_26484858.html

thanks! please wait for the moderator's response. anyway you are awarded :-)

Raj
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
sedgwick,

Please check this related question
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26487580.html

I tried the way you suggested here, but not working.

Regards
Raj
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
sedgwick,

Thanks for your quick response and help with my related question. :-) Great!!

Thanks
Raj
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.