Search code examples
c#asp.netxmlxmlreaderxmltextwriter

I want to edit xml file


alt text

I have modified the structure of d xml file. i want to edit value of visible


Solution

  • You can use such code pattern:

    bool foobar()
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(FileName);
                XmlNodeList ns = doc.SelectNodes("a/d/e/f");
                if (ns.Count == 1)
                {
    
                        ns[0].Attributes["visible"].Value = true;
                        doc.Save(FileName);
                        return (true);
                }
                else
                    return (false);
            }
            catch (Exception e)
            {
                return (false);
            }
        }