문제

alt text

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

도움이 되었습니까?

해결책

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);
        }
    }

다른 팁

Well, LINQ to XML makes it very easy to manipulate XML documents, assuming they're small enough to be sensibly loaded into memory.

For example:

var doc = XDocument.Load("Foo.xml");
foreach (var element in doc.Descendants("c"))
{
    element.SetAttributeValue("value", "bb");
}
doc.Save("Bar.xml");

Now that will set the value attribute for every c element. It's not clear whether or not that's what you want. If it's not, please edit your question to make it more specific.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top