Click here to Skip to main content
15,847,583 members
Home / Discussions / C#
   

C#

 
Questionmatching exact word c# Pin
Love Allah19-Sep-17 13:42
Love Allah19-Sep-17 13:42 
AnswerRe: matching exact word c# Pin
PIEBALDconsult19-Sep-17 13:45
mvePIEBALDconsult19-Sep-17 13:45 
GeneralRe: matching exact word c# Pin
Love Allah19-Sep-17 14:00
Love Allah19-Sep-17 14:00 
AnswerRe: matching exact word c# Pin
OriginalGriff19-Sep-17 21:02
mveOriginalGriff19-Sep-17 21:02 
QuestionHow to handle multiple exceptions(Try..Catch) Pin
Bootzilla3319-Sep-17 5:55
Bootzilla3319-Sep-17 5:55 
SuggestionRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming19-Sep-17 6:22
mveRichard Deeming19-Sep-17 6:22 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3319-Sep-17 6:32
Bootzilla3319-Sep-17 6:32 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming19-Sep-17 6:57
mveRichard Deeming19-Sep-17 6:57 
Firstly, that's not a valid XML document. You either need to remove the closing </AmazonTrackingResponse> tag, or insert the opening tag.

Secondly, you would read it in the same way as any other XML document:
C#
var rspxml = XDocument.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?><AmazonTrackingResponse><TrackingErrorInfo><TrackingNumber>12345678</TrackingNumber><TrackingErrorDetail><ErrorDetailCode>ERROR_101</ErrorDetailCode><ErrorDetailCodeDesc>INVALID TRACKING NUMBER</ErrorDetailCodeDesc></TrackingErrorDetail></TrackingErrorInfo></AmazonTrackingResponse>");

var errorInfo = rspxml.Descendants("TrackingErrorInfo").FirstOrDefault();
if (errorInfo != null)
{
    string trackingNumber = (string)errorInfo.Element("TrackingNumber");
    
    var detail = errorInfo.Element("TrackingErrorDetail");
    if (detail != null)
    {
        string errorCode = (string)detail.Element("ErrorDetailCode");
        string errorMessage = (string)detail.Element("ErrorDetailCodeDesc");
        // Do something with the error details...
    }
}


As for the XmlDocument vs XDocument, I'd suggest choosing one and sticking to it. The XDocument is generally easier to work with.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3319-Sep-17 7:05
Bootzilla3319-Sep-17 7:05 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3319-Sep-17 10:58
Bootzilla3319-Sep-17 10:58 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
eddieangel19-Sep-17 13:18
eddieangel19-Sep-17 13:18 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3320-Sep-17 3:56
Bootzilla3320-Sep-17 3:56 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming20-Sep-17 11:01
mveRichard Deeming20-Sep-17 11:01 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 4:58
Bootzilla3321-Sep-17 4:58 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming21-Sep-17 5:32
mveRichard Deeming21-Sep-17 5:32 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 5:52
Bootzilla3321-Sep-17 5:52 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming21-Sep-17 6:18
mveRichard Deeming21-Sep-17 6:18 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 6:41
Bootzilla3321-Sep-17 6:41 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming21-Sep-17 7:07
mveRichard Deeming21-Sep-17 7:07 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 7:15
Bootzilla3321-Sep-17 7:15 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Richard Deeming21-Sep-17 7:19
mveRichard Deeming21-Sep-17 7:19 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 7:40
Bootzilla3321-Sep-17 7:40 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3321-Sep-17 19:19
Bootzilla3321-Sep-17 19:19 
GeneralRe: How to handle multiple exceptions(Try..Catch) Pin
Bootzilla3322-Sep-17 3:54
Bootzilla3322-Sep-17 3:54 
AnswerRe: How to handle multiple exceptions(Try..Catch) Pin
eddieangel19-Sep-17 7:07
eddieangel19-Sep-17 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.