0

I am using BaseX to store XML data with multiple nodes in the following format:

<root>
  <item id="65816" parent_id="45761" type="test">
    <content>
      <name>Name of my node on the tree</name>
    </content>
  </item>
</root>

The code above is essentially one typical node under 'root'. Now, I am trying to delete a node based on the 'id' property of the 'Item' object.

I looked at the documentation on BaseX.org but that does not explicitly tell me how to deal with nodes which have IDs linked to it. I am trying to something like this:

XQUERY delete node //root/item.id="65816"

Note: The above line doesn't work. That is just to give an idea of what I am trying to achieve.

  • 1
    Assuming that you need a valid XPath expression to specify the node to be deleted could you try `XQUERY delete node //root/item[@id="65816"]` – Marcus Rickert Oct 19 '14 at 21:08
  • Your answer looked promising until I tried. Unfortunately, it does not work and returns this message: `Stopped at , 1/12: Syntax: DELETE [path] Delete resources from database. Deletes resources from the currently opened database.` – supersophisticated Oct 20 '14 at 00:24
  • You did not specify XQUERY when you executed the command given by Marcus. XQUERY is the database command telling BaseX everything that follows is an XQuery. Instead, it used the database command delete, which tries to delete documents from a database, i.e. it expects a path. – dirkk Oct 20 '14 at 08:07
  • 2
    Also, you might want to take a look at our documentation for XQuery Updates, which also shows how to delete nodes and also shows some basic deletes: http://docs.basex.org/wiki/XQuery_Update#delete. However, you might want to get familiar with XQuery/XPath before, as using @ to access attributes is a very basic features and XQuery offers you much, much more – dirkk Oct 20 '14 at 08:09
  • Thanks for pointing it out dirk. That was silly of me to miss using XQUERY. Marcus - your answer was what I was looking for indeed. Thanks – supersophisticated Oct 21 '14 at 01:58

0 Answers0