Solved

XML search and replace

Posted on 2013-10-25
1
192 Views
Last Modified: 2015-01-13
I have an XML document with the following dates and periods.  It is run twice a month.

An example of the lines are as follows:

<DOC_REC_DT_DC Attribute="Y"><![CDATA[2013-10-15]]></DOC_REC_DT_DC>
<DOC_PER_DC Attribute="Y"><![CDATA[1]]></DOC_PER_DC>
<BFY Attribute="Y"><![CDATA[2014]]></BFY>

There are about 10 different dates that have to be changed and each of these lines are in the document an unknown number of times.  For example, doing this manually, I find the first occurrence of <DOC_REC_DT_DC... and replace all with the same text except for changing the date from 2013-10-15 to the current date.

I would like to automate this so it doesn't have to be done manually.

I don't know xml so I'd like to use a batch file or some reliable utility.

Thank you for your help.
0
Comment
Question by:schowning
1 Comment
 
LVL 10

Accepted Solution

by:
mark_harris231 earned 500 total points
ID: 39601479
I would suggest using a text editor like Programmer's Notepad (www.pnotepad.org) and use the built-in regular expression functionality in the Search/Replace.

If all dates in the document need to be replaced with the current date, you can use this search pattern:

\d{4}-\d{2}-\d{2}

Enter the current date in the replace field and all instances of a date in the format of YYYY-MM-DD will be replaced with the current date.

If there are dates that should not be changed, in addition to those that should, then you want to use a more specific search pattern:

e.g.,

Search Pattern
(<DOC_REC_DT_DC Attribute="Y"><!\[CDATA\[)\d{4}-\d{2}-\d{2}

Replace Pattern
\1<current date>    

(replace "<current date>" with the actual date value)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now