0

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", value);
            }
            // 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='"
1

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, does single slash mean anything, is this a c# or xml thing where i can look it up
This is an XML query language called xpath...have a look at the provided links.
@JackOfAllTrades & @BoltClock +1 for the links.
2

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'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.