Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# code to read data from this XML file

Posted on 2010-09-20
10
Medium Priority
?
1,101 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Rajkumar Gs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 33714706
//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
 
LVL 42

Assisted Solution

by:Meir Rivkin
Meir Rivkin earned 2000 total points
ID: 33714707
use the following code to load the xml into XmlDocument:

XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(@"<xml_file>");
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33714747
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
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
LVL 42

Assisted Solution

by:Meir Rivkin
Meir Rivkin earned 2000 total points
ID: 33714774
here:

XmlNodeList list = xmldoc.SelectNodes("//informationStatus/@status");
            string status = list.Item(1).InnerText;
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 33714818
@RajkumarGS

you could simply accept one of my comments as a solution instead of splitting... :-)
10x for the points anyway
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33714931
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33722989
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33723336
sedgwick,

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

Thanks
Raj
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33743299
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 33751964
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question