Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:11:06+00:00 2026-05-28T22:11:06+00:00

I am calling a function which returns a string containing XML data. How this

  • 0

I am calling a function which returns a string containing XML data. How this function works is not important but the resulting xml can be different depending on the success of the function.

Basically the function will return either the expect XML or an error formatted XML. Below are basic samples of what the two results might look like…

On Success:

<SpecificResult>
    <Something>data</Something>
</SpecificResult>

On Error:

<ErrorResult>
    <ErrorCode>1</ErrorCode>
    <ErrorMessage>An Error</ErrorMessage>
</ErrorResult>

The way my system is set up is that I can convert an xml string to a class with a simple converter function but this requires my to know the class type. On success, I will know it is SpecificResult and I can convert. But I want to check to first if an error occured.

The ideal end result would allow something similar to this…

string xml = GetXML();
if(!IsError(xml))
{
   //convert to known type and process
}

So the question is, what is the best way to implement the IsError function?

I have thought of a couple of options but not sure if I like any of them really…

  1. check if xml string contains "<ErrorResult>"
  2. try to convert xml to ErrorResult class and check for fail
  3. use XDocument or similar built in functions to parse the tree and search for ErrorResult node
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:11:06+00:00Added an answer on May 28, 2026 at 10:11 pm

    Since the GetXml() method is essentially returning untyped data and the only safe assumption here is that it’s structured as XML, the safest way to assert its actual type would be to parse it as XML:

    private bool IsError(string xml)
    {
        var document = XDocument.Parse(xml);
        return document.Element("ErrorResult") != null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return a value from (transport) to the calling function, but can't
I'm calling a function from a native DLL which returns a char* pointer, how
I am calling a DLL using PInvoke. The DLL's function returns a C string
I have a C++ function which returns a multi-line std::string . In the test-case
I am trying to return a C string from a function, but it's not
I've created a simple C# asp.net web service function which returns a string message
Iam calling a PHP custom function with different parameters which returns a different arrays
which function windows is calling to list the files in a directory ? thanks
I have got a problem with calling a global function, which takes a pointer
I have a javascript function for checking errors which I am calling on OnClicentClick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.