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 6602477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:52:54+00:00 2026-05-25T18:52:54+00:00

I am trying to read XML files from different machines, some of these files

  • 0

I am trying to read XML files from different machines, some of these files may have data elements that others don’t have. Currently, I am using a Try-Catch block to handle these situations but I was wondering if there was a better way of doing this, any thoughts?

XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml("MachineData.xml");

   DataSet ds = new DataSet("AppData");
   ds = xmlDatadoc.DataSet;

   DataView dv = new DataView(ds.Tables[config.GlobalVars.Paths]);
   foreach (DataRowView drv in dv)
   {
      try
      {
         cApp.TransferProtcol = drv["TransferProtocol"].ToString();
      }
      catch { }

      try
      {
         cApp.RemoteServerPath = drv["RemoteServer"].ToString();
      }
      catch { }
   }

Ok, I figured out a solution based upon John Saunders post:

     if(ds.Tables[0].Columns.Contains("TransferProtocol")
     {
          try
          {
             if (drv["TransferProtocol"].ToString().Length > 0)
             {
                 cApp.TransferProtcol = drv["TransferProtocol"].ToString();
             }
          }
          catch(Exception e)
          {
             Messagebox.Show(e.Message);
          }
     }

I agree about the empty Catch blocks but I stubbed them out for testing purposes. I have since edited my post as to what my Try-Catch block looks now.

  • 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-25T18:52:54+00:00Added an answer on May 25, 2026 at 6:52 pm

    That’s a horrible way to “handle” the problem. If the XML may legitimately be missing elements, then check to see if the elements are present before trying to access them.

    Your empty catch blocks ignore all exceptions that occur inside of them, not just exceptions that mean the element is missing.


    The columns are present or not as soon as the table is loaded. You can use ds.Tables[config.GlobalVars.Paths].Columns.Contains("columnName") to determine whether or not the column exists.

    If a column exists, then for any given row, the column may or may not be null. Use drv.Row.IsNull("columnName") to determine whether that column in that row is null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file(from federal government's data.gov) which I'm trying to read with
I have an XML file that I'm trying to read from here , and
I'm trying to read in some sample data from an XML file in a
Got a project that collects data as XML files from a particular system (these
I have a controller that I am trying to grab XML files from remote
I am trying to read some data from my XML file Names/Name/trckid 1) For
I'm trying to generate POJO's from mapping xml files. I read something about adding
I have one .net windows application I'm trying to read .xml file from c#
I'm trying to read data from an xml file and display it in a
I'm trying to read the data from an XML file, validating it against the

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.