Appendix A. Updating Documents with XmlModify

The best way to update or modify a document from within BDB XML is to use XQuery Update statements. See Modifying XML Documents for an introduction to that topic.

However, in the past BDB XML offered the XmlModify API for modifying existing documents. Though deprecated, this API is still available in the library. This appendix provides an introduction to it.

Essentially, you can use XmlModify methods to identify a series of modification steps to be taken against a document. These steps allow you to add, delete, rename, and replace document nodes. You can also manipulate comments and processing instructions.

Once you have finished identifying the modification steps that you want to perform, you use XmlModify::execute() to apply the modifications to either a single document (by passing it an XmlValue object), or a set of documents (by passing it an XmlResults object).

Modification Parameters

There are a common set of parameters to the XmlModify modification methods that are worth examining before proceeding. These arguments have roughly the same meaning, regardless of the modification action being requested. They appear on the modification methods in the following order:

  • XmlQueryExpression selectionExpr

    This parameter contains an XQuery expression that selects the portion of the document to be modified. For example, if you want to rename a node, then this expression would select the node that you want to rename.

  • XmlObject type

    This parameter identifies the type of information you are inserting into the document. That is, you use this parameter to indicate whether you are inserting an element node, an attribute node, text node, a processing instruction, or a comment. See the API Reference documentation for information on how to specify these types.

  • std::string name

    Identifies the name of the information you are inserting. For example, if you are inserting an element or attribute node, then this provides the name of that node. The value of this parameter is ignored if you are inserting a text or comment node.

  • std::string content

    Identifies the content that you are inserting. If you are inserting an element node, then this must contain either a text node, or a valid child content for the node. For attribute nodes, this contains the value to which the parameter is equal. For processing instructions, this contains all of the information that appears in the processing instruction other than the processing instruction's name.