Replace single XML node value
Posted: Tue Aug 14, 2018 4:34 pm
We have a few different types of XML files coming through a workflow. There could be a mix of files coming through the flow, but we're not really concerned with what type of XML it is, they all have a <journal-id> with a few samples below of how this appears.
<journal-id journal-id-type="publisher-id">jns</journal-id>
<journal-id journal-id-type="nlm-ta">J Neurosurg</journal-id>
We basically need to just replace whatever is in the <journal-id> tag with "j-neurosurg", so we'd get this:
<journal-id journal-id-type="publisher-id">j-neurosurg</journal-id>
<journal-id journal-id-type="nlm-ta">j-neurosurg</journal-id>
The rest of the file would stay exactly as it is. I originally thought of using MapForce to do this and then send the files back into SWITCH to be assembled, but the different number of schemas will make this quite complex in MapForce so I was hoping for a way to just keep everything in the file as is except changing that one value using a script within SWITCH. Is that possible?
<journal-id journal-id-type="publisher-id">jns</journal-id>
<journal-id journal-id-type="nlm-ta">J Neurosurg</journal-id>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE issue-xml PUBLIC "-//Atypon//DTD Systems Archival NLM DTD Suite Issue XML DTD v2.2.0 20090301//EN" "atyp.dtd">
<issue-xml>
<journal-meta>
<journal-id journal-id-type="publisher-id">jns</journal-id>
<journal-title>SAMPLE</journal-title>
<issn pub-type="ppub">0022-3085</issn>
<issn pub-type="epub">1933-0693</issn>
<publisher>
<publisher-name>SAMPLE</publisher-name>
</publisher>
</journal-meta>
<issue-meta>
<pub-date pub-type="ppub">
<month>12</month>
<year>2016</year>
</pub-date>
<volume>125</volume>
<issue>6</issue>
<issue-id pub-id-type="doi">10.3171/jns.2016.125.issue-6</issue-id>
<issue-title>Pages 1325-1617</issue-title>
</issue-meta>
</issue-xml>
<journal-id journal-id-type="publisher-id">j-neurosurg</journal-id>
<journal-id journal-id-type="nlm-ta">j-neurosurg</journal-id>
The rest of the file would stay exactly as it is. I originally thought of using MapForce to do this and then send the files back into SWITCH to be assembled, but the different number of schemas will make this quite complex in MapForce so I was hoping for a way to just keep everything in the file as is except changing that one value using a script within SWITCH. Is that possible?