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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:01:08+00:00 2026-06-13T00:01:08+00:00

I was asked today to look at a new project – reading in some

  • 0

I was asked today to look at a new project – reading in some XML and doing some analysis. I know a little C#. I have gotten this far with this code that so far works. I get the 4 node lists successfully. I have a couple problems. First I am not sure how to access what is in the tag on any of the nodes in any of the lists. Second, I’d prefer to be able to use LINQ queries but XmlNodeList doesn’t seem to support that syntax. In the sample XML below, I’d like to be able to get all the vdisks that belong to a particular IO Group or mdisk as determined by io_group_name or mdisk_grp_name property. Most of what I looked at gave examples for accessing the [Attribute] list and searches all used properties/atttributes interchanged.

What I tried is also below, it gave a null value exception. The Attributes list only has one attribute. I can’t find any examples to do what I want and it isn’t clear from inspecting the node in the debugger what I need to access to do what I want.

//this works

XmlTextReader reader = new XmlTextReader(_InputFile);
XmlDocument doc = new XmlDocument();
doc.Load(reader);

XmlNodeList clusterlist = doc.SelectNodes("//object[@type='cluster']");
XmlNodeList controllerlist = doc.SelectNodes("//object[@type='controller']");
XmlNodeList mdisklist = doc.SelectNodes("//object[@type='mdisk']");
XmlNodeList vdisklist = doc.SelectNodes("//object[@type='vdisk']");


// this did not work - got null value exception
foreach (XmlNode vdisknode in vdisklist)
{
    string str = vdisknode.Attributes["mdisk_grp_name"].Value;
}

A sample of the XML:

<object type="vdisk">
     <property name="id" value="0" />
     <property name="name" value="nim01_vd06_gmt" />
     <property name="IO_group_id" value="0" />
     <property name="IO_group_name" value="ossvc06_iogrp0" />
     <property name="status" value="online" />
     <property name="mdisk_grp_id" value="0" />
     <property name="mdisk_grp_name" value="T1_OSIBM06_MDG1" />
     <property name="capacity" value="644245094400" />
     <property name="type" value="striped" />
</object>
  • 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-13T00:01:09+00:00Added an answer on June 13, 2026 at 12:01 am

    object node has only one attribute: type

    string type = vdiskNode.Attributes["type"].Value;
    

    property node has two attributes: name and value:

    string name = propertyNode.Attributes["name"].Value;
    string value = propertyNode.Attributes["value"].Value;
    

    What you need I deem is to extend the XPath query:

    "//object[@type='vdisk']/property[@name='mdisk_grp_name']/@value"
    

    Or use LINQ to XML:

    from obj in doc.Load(xml).Root.Elements("object")
    where (string)obj.Attribute("type") == "vdisk"
    from prop in obj.Elements("property")
    //where (string)prop.Attribute("name") == name
    select prop.Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some of the responses to a question I asked today earlier today have caused
I already asked a question today : This one Now I have a code
I was asked this today and i know the answer is damn sure simple
I have used try-catch/except-finally variants in many languages for years, today someone asked me
This is a sequel to my (other) dumb question that I have asked today
Earlier today I asked this question . After spending some time investigating this issue,
a client asked me today about having users be able to have their own
I have been asked this question today. When debugging, there is an error. But
I'm new to PHP and I have this homework to do. The teacher asked
So I just got asked this at an interview today and after some googling

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.