Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read xml attributes in ASP.NET

Status
Not open for further replies.

raghu3

Programmer
Dec 19, 2005
96
US
Sounds fairly straight:
I have a xml file with user created attributes:
<ou Text="test" img="Folder.Gif" exp="True" url="" cn="cc\cc\cc" >

How do I access the user defined attribites? text,cn ...
Thanks,
 
Thanks for clearing the mix up of attribute-elements.
will try the examples in thread.

-raghu
 
Does not work for me as my XML has good number of nestings.
the c# code looks condusing as I do not know _data(0,0) ??
Any suggestions:
 
Code:
XmlDocument xml = new XmlDocument();
xml.Load("test.xml");
XmlNodeList attributes = xml.SelectNodes("blah/blah/ou/@*");
foreach(XmlNode attribute in attributes)
{
    //Do stuff with each attribute
}

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks JontyMC. This will not work for me as I have many nested OUs, see sample below.
The nesting levels can go upto 6.

Now I have to figure out hoe deep should the :
xml.SelectNodes("blah/blah/ou/@*") should go. I have to re-visit the design.

<ou text= .....>
<ou text= .....>
<ou text= .....>

</ou>
<ou text= .....>
<ou text= .....>
</ou>
<ou text= .....>
<ou text= .....>
<ou text= .....>
</ou>
Appreciate your help.
 
You can use the descendant-or-self XPath axis:
Code:
XmlNodeList attributes = xml.SelectNodes("//@*");

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top