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

  • Home
  • SEARCH
  • 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 8297335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:22:50+00:00 2026-06-08T15:22:50+00:00

I need some help with reading an oddly-formatted XML file. Because of the way

  • 0

I need some help with reading an oddly-formatted XML file. Because of the way the nodes and attributes are structured, I keep running into XMLException errors (at least, that’s what the output window is telling me; my breakpoints refuse to fire so that I can check it). Anyway, here’s the XML. Anyone experienced anything like this before?

<ApplicationMonitoring>
<MonitoredApps>
        <Application>
            <function1 listenPort="5000"/>
        </Application>
        <Application>
            <function2 listenPort="6000"/>
        </Application>
</MonitoredApps>
<MIBs>
    <site1 location="test.mib"/>
</MIBs> 
<Community value="public"/>
<proxyAgent listenPort="161" timeOut="2"/>
</ApplicationMonitoring>

Cheers

EDIT: Current version of the parsing code (file path shortened – Im not actually using this one):

XmlDocument xml = new XmlDocument();
xml.LoadXml(@"..\..\..\ApplicationMonitoring.xml");

string port = xml.DocumentElement["proxyAgent"].InnerText;
  • 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-06-08T15:22:55+00:00Added an answer on June 8, 2026 at 3:22 pm

    Your problem in loading the XML is that xml.LoadXml expects you to pass the xml document as a string, not a file reference.

    Try instead using:

    xml.Load(@"..\..\..\ApplicationMonitoring.xml");
    

    Essentially in your original code you are telling it that your xml document is

    ..\..\..\ApplicationMonitoring.xml
    

    And I’m sure you can now see why there is a parse exception. 🙂 I’ve tested this with your xml document and the modified load and it works fine (except for the issue that Only Bolivian Here pointed out with the fact that your inner Text is not going to return anything.

    For completeness you probably want:

    XmlDocument xml = new XmlDocument();
    xml.Load(@"..\..\..\ApplicationMonitoring.xml");
    string port = xml.DocumentElement["proxyAgent"].Attributes["listenPort"].Value;
    //And to get stuff more specifically in the tree something like this
    string function1 = xml.SelectSingleNode("//function1").Attributes["listenPort"].Value;
    

    Note the use of the Value property on the attribute and not the ToString method which won’t do what you are expecting.

    Exactly how you extract the data from the xml is probably dependant on what you are doing with it. For example you may want to get a list of Application nodes to enumerate over with a foreach by doing this xml.SelectNodes("//Application").

    If you are having trouble with extdacting stuff though that is probably the scope of a different question since this was just about how to get the XML document loaded.

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

Sidebar

Related Questions

I need some help reading data from a text file into my ArrayList .
I need some help using Linq to xml, I've been reading online articles but
After searching online and reading the Oracle documentation for this, I need some help
I need some logic/programming help with reading more than one record from a text
I've really hit a wall and am need of some help! Thankyou for reading
I need some help with Mule 3 esb. I am reading a message from
I need some help on something. I am reading some data from an Excel
I need some help with reading cookies. My website is bilingual, and as I
I'm trying to parse a binary file, and I need some help on where
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via

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.