Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>1. How to fix the XPath expression ?</h2> <p>Either of these will fix the query:</p> <p>1) Add the following line after creating the dom:</p> <pre><code> Doc.setProperty('SelectionLanguage', 'XPath'); </code></pre> <p>2) Better yet, you could be more explicit about which version of the parser you are creating and replace your construction line with this:</p> <pre><code>Doc := CoDOMDocument60.Create; </code></pre> <p>If the query doesn't find anything, Node will be empty.</p> <pre><code>if not Assigned(Node) then... </code></pre> <p>The default query language for the MSXML3 parser is XSLPatterns. You needed to explicitly set it to XPath. It's been a while since I've had to deal with it, but I assume the CreateOleObject line must create the MSXML parser my default.</p> <p>Update: Solution for the second half of your question stolen shamelessly (with permission) from the gracious TLama. :)</p> <h2>2. How to add a "control" node ?</h2> <p>Ignoring target document formatting and error handling e.g. this way:</p> <pre><code>procedure TForm1.Button2Click(Sender: TObject); var XMLRoot: IXMLDOMNode; XMLChild: IXMLDOMNode; XMLDocument: IXMLDOMDocument2; begin XMLDocument := CreateOleObject('Microsoft.XMLDOM') as IXMLDomDocument2; XMLDocument.load('XMLFile.xml'); XMLRoot := XMLDocument.selectSingleNode('//role/access'); if Assigned(XMLRoot) then begin XMLRoot := XMLRoot.appendChild(XMLDocument.createElement('control')); XMLChild := XMLRoot.appendChild(XMLDocument.createElement('type')); XMLChild.text := 'user'; XMLChild := XMLRoot.appendChild(XMLDocument.createElement('object')); XMLChild.text := 'COMPUTER\TLama'; XMLDocument.save('XMLFile.xml'); end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload