开发者

xml help using xpath string

开发者 https://www.devze.com 2023-03-12 00:13 出处:网络
found the following code: XmlDocument cfgDoc = new XmlDocument(); loadConfigDoc(cfgDoc); // retrieve the appSettings node

found the following code:

XmlDocument cfgDoc = new XmlDocument();
        loadConfigDoc(cfgDoc);
        // retrieve the appSettings node 
        node = cfgDoc.SelectSingleNode("//ETicketMailboxSettings");

        if (node == null)
        {
            throw new System.InvalidOperationException("appSettings section not found");
        }

        try
        {
            // XPath select setting "add" element that contains this key    
            XmlElement addElem = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");
            if (addElem != null)
            {
                addElem.SetAttribute("value", v开发者_开发问答alue);
            }
            // not found, so we need to add the element, key and value
            else
            {
                XmlElement entry = cfgDoc.CreateElement("add");
                entry.SetAttribute("key", key);
                entry.SetAttribute("value", value);
                node.AppendChild(entry);
            }
            //save it
            saveConfigDoc(cfgDoc, docName);
            return true;
        }
        catch
        {
            return false;
        }

what do the double slashes tell the compiler?

.SelectSingleNode("//add[@key='"


To look anywhere in the XML document. This is an XML query language.

A single slash would look from the root of an XML document.


Selects all nodes (in this case nodes named add with a specific attribute key) in the entire document.

A single slash means 'matching from the root of the document'.

0

精彩评论

暂无评论...
验证码 换一张
取 消