1

Im having trouble reading attribute strings while using XmlDocument to read thro child nodes. To be more specific, im trying to read an XML containing a list of running processes:

<Process_List>
  <Processes>
    <ibmpmsvc ID_1="860" />
    <svchost ID_2="8616" />
    <chrome ID_4="4300" />
    <SearchIndexer ID_5="3868" />
    <smss ID_6="416" />
  </processes>
</Process_List>

Each start element presents a running process along with its ID (and some other stuff later on).

So Im using XmlDocument to read thro each child node of /Process_List/Processes:

XmlNodeList xnList = xml.SelectNodes("/Process_List/Processes");
foreach (XmlNode xn in xnList)
{
    XmlNodeList cxnList = xn.ChildNodes;
    foreach (XmlNode child in cxnList)
    {
        listProc1.Add(child.Name.ToString());
    }
}

Problem is, Im only getting the child's name, (ibmpmsvc, svchost , chrome) and can't figure out how to get its other attributes.

thanks!

2
  • Tried Child.attribute ?? Commented Feb 7, 2013 at 12:50
  • 1
    What do you want to add to listProc1? Concatenated string? And why you can't use Linq to Xml? Commented Feb 7, 2013 at 12:50

2 Answers 2

2

You can use child.Attributes for that.

Sign up to request clarification or add additional context in comments.

Comments

2

Take a look at the the XMLNode C# Class for an overview of what properties are available to you : http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.aspx

listProc1.Add(child.Name.ToString());

Will only give you the Name of the element, which is what you are receiving. You need to also look at the .Value property and .Attributes (which in turn can be Enumerated through).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.