AddNodeAttribute will add an XML attribute to a targeted XML node within the XML document structure of a specified XML file. This can be useful for long-term data storage and modification.
The process accomplishes this by first loading the XML document structure from the specified file, and then attempting to add the attribute. It uses the provided XPath expression to locate the target node and then attempts to add the new attribute; replacing any previously-existing attribute of that node which has the same name as the new attribute. Afterwards, it saves the XML structure back to the file.
If the specified XPath cannot be evaluated to find a parent node, then an exception is thrown with the message “Node path <your xpath expression> could not be found.” This could mean that the targeted node which you are trying to locate does not exist or that the XPath expression specified does not target a node or is invalid.
AddNodeAttribute Use Examples
Basic AddNode Use
AddNodeAttribute Service Input
For this example, we have set up the following file, named “test.xml,” in the “C:\EASYProcess” directory on the local machine.
When run, the AddNodeAttribute service will load the XML document structure of the given file and add the user-specified XML attribute to the target node, within the XML structure. In this example, we are simply adding a (new) attribute called “name” to a node named “Element” which is a child of “Document.” Here is the same file after the service has run:
For clarity, we have added two LoadFromFile service blocks in order to display what the file looks like before and after the changes.