Search code examples
xmlxpathmsxml

Is it possible to create new xml elements with XPath using MSXML DOM? How?


Is it possible to create new xml elements with XPath(or another kind of path) using MSXML DOM? (function names are imaginary but understandable)

Something like:

node n = document.create_node("library/book/title");
n.set_value("Perfect code")

should create:

<library>
    <book>
        <title>Perfect code</title>
    </book>
</library>

The main point here is to create hierarchy in one line library/book/title.


Solution

  • It's not possible to create nodes using XPath. It is possible using XQuery, if you want to call that "another kind of path". I don't know specifically if there are XQuery implementations that run against the MSXML DOM, but it seems likely. (Though probably not from Microsoft.)