xml... attribute reading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • komi
    New Member
    • Mar 2007
    • 1

    xml... attribute reading

    <Root>
    <Family ID="1">
    <Member Name="Abe" DOB="3/31/42" />
    <Member Name="Betty" DOB="2/4/49" />
    <Member Name="Cathy" DOB="12/2/78" />
    <Member Name="Dan" Father="Abe" Mother="Betty" DOB="6/12/73" />
    </Family>
    <Family ID="2">
    <Member Name="Edith" Father="Abe" Mother="Betty" DOB="8/30/80" />
    <Member Name="Frank" DOB="11/4/70" />
    <Member Name="George" Father="Dan" Mother="Cathy" DOB="5/13/94" />
    <Member Name="Harold" Father="Dan" Mother="Cathy" DOB="7/1/97" />
    <Member Name="Irwin" Father="Frank" Mother="Edith" DOB="10/31/01" />
    <Member Name="Janet" Father="Frank" Mother="Edith" DOB="1/17/03" />
    </Family>
    </Root>


    This is my Xml file.I want to seperate every family tag by using it's ID attribute and also i want to read the attributes from Member elements.i write a code for this But i am getting error.I am using framework 2.0 and c#.In vb.net there is a property named ItemOf,but in c# it's not existing.So any body help me.Thanks in advance
  • sani723
    New Member
    • Feb 2007
    • 117

    #2
    XmlNodeList xmlnode = xmldoc.GetEleme ntsByTagName("F amily");
    for(int i=0;i<xmlnode.C ount;i++)
    {
    XmlAttributeCol lection xmlattrc = xmlnode[i].Attributes;
    if (xmlattrc[0].Value == 1)
    {
    // now here read the "Member Node's attributes"
    }

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      ItemOf VB property is designated as the C# indexer.
      For example, calling SelectNodes() on an XML element returns a XmlNodeList object. You can index into this collection using square parenthesis.

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        Hi,
        Did you succeed to solve the problem ?
        If yes, please let me know, in order to close the thread.
        Thanks,
        Dorin.

        Comment

        Working...