none
Commit changes on xmldocument RRS feed

  • Question

  • Hello,

     

    I have this function that add attributes to xmlnode of an xmldocument, and i need to commit these changes on the xmldocument, I tried the xmldocument.save() that i call after every attribute addition, the problem is that after checking the document i found that the new attributes are added to the last node, though the attributes are added to all the nodes..

    here is the code i wrote:

     

    public void checkChild(XmlNode node, XmlDocument doc)

    {

    XmlAttribute rightToLeft = doc.CreateAttribute("IsRightToLeft");

    rightToLeft.Value = "true";

    XmlAttribute isUniCode = doc.CreateAttribute("IsUnicode");

    isUniCode.Value = "true";

    foreach (XmlNode n in node)

    {

    if (n.Name.Equals("Segment"))

    {

    if (n.Attributes["IsRightToLeft"] == null)

    {

    n.Attributes.Append(rightToLeft);

    }

    if (n.Attributes["IsUnicode"] == null)

    {

    n.Attributes.Append(isUniCode);

    }

    //save the changes

    doc.Save("out.xml");

    }

    else

    checkChild(n,doc);

    }

    }

     

    any idea if there is another way to commit the changes??

    Tuesday, March 25, 2008 8:54 AM

Answers

  • Its working fine now i just had to creat the same attribute each time i wanted to add it to the node..

     

    if (n.Attributes["IsRightToLeft"] == null)

    {

    //create new instance righttoLeft

    XmlAttribute rightToLeft = doc.CreateAttribute("IsRightToLeft");

    rightToLeft.Value = "true";

    n.Attributes.Append(rightToLeft);

    }

    if (n.Attributes["IsUnicode"] == null)

    {

    //create new instace of inUniCode

    XmlAttribute isUniCode = doc.CreateAttribute("IsUnicode");

    isUniCode.Value = "true";

    n.Attributes.Append(isUniCode);

    }

     

    I hope u find this helpful guyzz

     

    salam

    Tuesday, March 25, 2008 11:49 AM