Click here to Skip to main content
15,917,061 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delete child in XML document while running an C# Application! Pin
Heath Stewart11-Jun-04 5:43
protectorHeath Stewart11-Jun-04 5:43 
GeneralRe: Delete child in XML document while running an C# Application! Pin
QzRz11-Jun-04 5:48
QzRz11-Jun-04 5:48 
GeneralSurely this is an Easy Question... Pin
Adam °Wimsatt11-Jun-04 4:56
Adam °Wimsatt11-Jun-04 4:56 
GeneralRe: Surely this is an Easy Question... Pin
Heath Stewart11-Jun-04 5:28
protectorHeath Stewart11-Jun-04 5:28 
GeneralAssembly Class Locking Issue Pin
Daniel M. Edwards11-Jun-04 4:49
Daniel M. Edwards11-Jun-04 4:49 
GeneralRe: Assembly Class Locking Issue Pin
Heath Stewart11-Jun-04 5:25
protectorHeath Stewart11-Jun-04 5:25 
GeneralRe: Assembly Class Locking Issue Pin
Daniel M. Edwards11-Jun-04 6:01
Daniel M. Edwards11-Jun-04 6:01 
GeneralPDA PC communication , IIS Pin
apenon11-Jun-04 4:25
apenon11-Jun-04 4:25 
GeneralDesign Question: Correct way to show data from mutliple DB tables Pin
James Spibey11-Jun-04 4:10
James Spibey11-Jun-04 4:10 
GeneralRe: Design Question: Correct way to show data from mutliple DB tables Pin
Michael Potter11-Jun-04 5:01
Michael Potter11-Jun-04 5:01 
GeneralRe: Design Question: Correct way to show data from mutliple DB tables Pin
James Spibey11-Jun-04 5:52
James Spibey11-Jun-04 5:52 
GeneralMicrosoft Excel Plugin Help Pin
Asad Hussain11-Jun-04 3:41
Asad Hussain11-Jun-04 3:41 
Generaltabpage events Pin
robmays11-Jun-04 2:07
robmays11-Jun-04 2:07 
GeneralRe: tabpage events Pin
Corinna John11-Jun-04 2:20
Corinna John11-Jun-04 2:20 
GeneralRe: tabpage events Pin
robmays11-Jun-04 20:45
robmays11-Jun-04 20:45 
Generalproblem in applying grid style to datagrid Pin
Anonymous11-Jun-04 2:06
Anonymous11-Jun-04 2:06 
GeneralRe: problem in applying grid style to datagrid Pin
Heath Stewart11-Jun-04 4:14
protectorHeath Stewart11-Jun-04 4:14 
GeneralReadin XML Attributes Pin
saud_a_k11-Jun-04 1:14
saud_a_k11-Jun-04 1:14 
GeneralRe: Readin XML Attributes Pin
Alex Getman11-Jun-04 2:45
Alex Getman11-Jun-04 2:45 
GeneralRe: Readin XML Attributes Pin
saud_a_k11-Jun-04 3:00
saud_a_k11-Jun-04 3:00 
GeneralRe: Readin XML Attributes Pin
Heath Stewart11-Jun-04 4:10
protectorHeath Stewart11-Jun-04 4:10 
GeneralRe: Readin XML Attributes Pin
saud_a_k13-Jun-04 20:55
saud_a_k13-Jun-04 20:55 
GeneralRe: Readin XML Attributes Pin
Heath Stewart14-Jun-04 3:40
protectorHeath Stewart14-Jun-04 3:40 
GeneralRe: Readin XML Attributes Pin
saud_a_k14-Jun-04 17:58
saud_a_k14-Jun-04 17:58 
I got this code on the net....


private void AddWithChildren(XmlNode xnod, Int32 intLevel)
{
//Adds a node to the ListBox, togather with its children.
//intLevel controls the depth of indenting
XmlNode xnodWorking;
String strIndent = new string(' ',2 * intLevel);
//Get the value of the node (if any)
string strValue = (string) xnod.Value;
if(strValue != null)
{
strValue = " : " + strValue;
}
//Add the node details to the ListBox
Console.WriteLine(strIndent + xnod.Name + strValue);

//For an element node, retrive the attributes
if (xnod.NodeType == XmlNodeType.Element)
{
XmlNamedNodeMap mapAttributes = xnod.Attributes;
//Add the attributes to the ListBox
foreach(XmlNode xnodAttribute in mapAttributes)
{
Console.WriteLine(strIndent + " " + xnodAttribute.Name +
" : " + xnodAttribute.Value);
}
//If there are any child node, call this procedrue recursively
if(xnod.HasChildNodes)
{
xnodWorking = xnod.FirstChild;
while (xnodWorking != null)
{
AddWithChildren(xnodWorking, intLevel +1);
xnodWorking = xnodWorking.NextSibling;
}
}
}
It workes fine but I thought it would be a little easier to get the attributes.. mainly those which are present in the same line as the element tag like
<person fname=nnn lname=hhh>
.....
</person>
Is there an easier way...

MaXx
GeneralRe: Readin XML Attributes Pin
Heath Stewart15-Jun-04 2:30
protectorHeath Stewart15-Jun-04 2:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.