Over a million developers have joined DZone.

Manipulating XML Files With XPath Strings in IBM UrbanCode Deploy

DZone's Guide to

Manipulating XML Files With XPath Strings in IBM UrbanCode Deploy

Are you looking to manipulate your XML files with your IBM UrbanCode Deploy server? If so, you are not alone!

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

I’m learning that people really want to manipulate XML files with their IBM UrbanCode Deploy servers! We get so many questions about the Update XML With XPath automation step (both through the forum and through direct contact) that I wrote an article about some common things that come up when people want to edit XML files as part of their deployment automation.

We still get a ton of XPath questions!

The most common use case seems to be a server configuration that needs an edit when a new application or version of an application gets deployed. However, this step can edit just about any XML file, though there are some gotchas and idiosyncrasies that are listed in the article. (I might go into some detail about those in a later post.)

The basics are pretty simple. First, you give the step the name and location of an XML file or files. Then, you give it some rules for changes to make in the XML file. To tell the step to change some text, for example, you give it an XPath string that points to the text, then a little text “arrow” (->), and then the new text.

For example, here’s some sample XML from the article:

<?xml version="1.0" encoding="UTF-8"?>
    <data name="filePath" value="/opt/sampleDirectory"/>
    <data name="textData">Here is some text.</data>
    <data att1="one" att2="two" name="attributes" value="something"/>

To change an attribute value, you use an XPath string that points to that attribute, and then you put in the new text. For example, to change the /opt/sampleDirectory to /usr/otherDirectory, put this in the Replace with text field: //testFile/myData/data[@value]/@value->/usr/otherDirectory 

To change the text of a node, refer to it as text(). For example: 

//testFile/myData/data[@name='textData']/text()->Some new text content.

There are also steps to add and remove XML nodes.

Got an unusual file that you need to make changes to as part of your deployment automation? Keep the XPath questions coming and we’ll answer as many as we can.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

xpath ,string ,xml ,urbancode deploy ,integration

Published at DZone with permission of Tim McMackin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}