Thursday, 6 November 2014

Create XML nodes using XPath



Is it possible to create XML nodes using XPath?


Assume i got the following XML:



<data>
<someValue1></someValue2>
<someValue2></someValue2>
<someArray>
<val></val>
<val></val>
<val></val>
</someArray>
</data>


What i am trying to do is getting a node inside the XML using XPath (e.g. /data/someValue1) and setting the value of the node. This is of course easy to achieve with any language and framework supporting XML + XPath.


But when my XPath expression is pointing to a non existing node I want to somehow create this node. Even if the XPath expression is more complex (e.g. /data/someArray/val[5]).


At best this automatic node creation should be supported by some library. Is there an easy way for what I am trying to achieve? Currently I am using C++ with QT and the QXmlQuery class.


No comments:

Post a Comment