Solved

XML search and replace

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
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…
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
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.

896 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

15 Experts available now in Live!

Get 1:1 Help Now