Update Form XML Overview
The Nintex form XML is a serialization of the Nintex Document Object Model. The XML describes the form and contains an inventory of layouts and controls used by the form. You can modify the XML. Provided the form XML remains valid you can then load the modified XML back into Nintex Forms with your updates.
Overview
This code sample walks through the use of the .NET Framework's XmlDocument class to use XPath to find and update the XML nodes.
The overall process follows these steps:
- Construct your XPath queries to identify your target nodes.
- Update the console application with the queries.
- Update the target node values with the updated values.
- Retrieve the form XML with the Nintex Forms Web Service. For more information, see Migrate Forms with the Nintex Forms Web Service API.
- Update the form XML by running your application.
- Publish the form XML with the Nintex Forms Web Service.
Caution: If the form XML is damaged in the update process, the Nintex Forms import will fail. If you import fails, you can refer to the XML Reference to troubleshoot your XML. For more information see XML Reference.
In a scenario where you might need to update many forms, you can write an application that can handle this bulk update. For instance, you may want to update repeated elements on many of your Nintex forms such as a banner graphic or label text. You could create an application that would use the Nintex Forms Web Service to retrieve your forms. And then your application would load the XML, perform the modifications on each file, save the file to a target location, and then upload the updated form using the web service.
Working with Nintex Forms and XPath
You will need to construct your XPath Queries by identifying the XPath query that will return the target node that you would like to modify. You may want to download the form XML and open the file in a tool that can read the XML document object model such as the XML tools in Visual Studio.
In creating your query, you have several options. For example, if your forms use a regular structure, and you can predict that you will always be update the 8th child node (FormControlProperties) in FormControls, then your query can specify the node number. For example your image control may be predictably found at this following XPath:
/n:Form/n:FormControls/d2p1:FormControlProperties[8]/d2p1:ImageUrl
Or, you may want to target a node by identifying an identifying attribute such as the control ID. For example:
/n:Form/n:FormControls/d2p1:FormControlProperties[1]/d2p1:UniqueId="564116a2-9bbb-41bf-89db-e19dcafb066a"
Nintex Forms Namespaces
The Nintex forms XML use a number of namespaces. This has the effect of making the Xpath queries complex. The.NET framework provides a class, XmlNameSpaceManager, to help resolve queries against XML in namespaces. The class resolves, adds, and removes namespaces to a collection and provides scope management for these namespaces. XmlNamespaceManager stores prefixes and namespaces as strings. For example, prefix "n" and namespace, "http://schemas.datacontract.org/2004/07/Nintex.Forms" can be declared as:
nsmgr.AddNamespace("n", "http://schemas.datacontract.org/2004/07/Nintex.Forms");
For more information about working with .Net and XML, see the following topics: