Solved

XML search and replace

Posted on 2013-10-25
1
199 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XSL-FO - show results in 2 columns 5 32
Determining Project Cost 1 78
MS SQL Database Generating XML using query 21 44
Post xml via PHP Soap Client 3 49
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

831 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