Solved

XML search and replace

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifiā€¦
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

820 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