Page 1 of 1

Replace single XML node value

Posted: Tue Aug 14, 2018 4:34 pm
by matt.baile
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>

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>
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?

Re: Replace single XML node value

Posted: Tue Aug 14, 2018 4:53 pm
by jan_suhr
You should be able to solve this with my apps "Make XML" or "Take notes".

Give them a try

Re: Replace single XML node value

Posted: Tue Aug 14, 2018 5:18 pm
by matt.baile
For some reason I keep getting a note saying that I need to sign into SWITCH in the "About" tab. I've done this, but still can't download a trial of the Make XML program. Any thoughts?

Is there a way just to keep the same XML file as is, but replace that one node and leave the rest as is?

Re: Replace single XML node value

Posted: Tue Aug 14, 2018 6:02 pm
by jan_suhr
Try to sign in here and assign it to your Switch server.

https://www.enfocus.com/en/appstore/overview

Re: Replace single XML node value

Posted: Tue Aug 14, 2018 6:22 pm
by cstevens
I've had a similar issue with the APP store, I think it has something to do with our firewall.

With the scripting module you can do something like this:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var xmlDoc = new Document(job.getPath());
	var journalIdNode = xmlDoc.evalToNode("/issue-xml/journal-meta/journal-id", null);
	var currentText = journalIdNode.getFirstChild();
	var newText = xmlDoc.createText("j-neurosurg");
	journalIdNode.replaceChild(newText, currentText);
	xmlDoc.save(job.getPath());
	job.sendToSingle(job.getPath());
}
That's assuming you have a specific XML structure though. If that journal-id value changes locations, or there are multiple journal-id elements in the file this might not work.

Re: Replace single XML node value

Posted: Tue Aug 14, 2018 8:31 pm
by matt.baile
It could be a firewall issue. I'll ask IT to investigate. When I sign in to the app store, it doesn't recognize any server or any installations for some reason.

The XML files going through this flow will have a few different structures, although the journal-id should always stay in the same place and I'll have multiple occurrences of this script as we have different journal titles going through different lanes of the flow. As far as I cans ee, the journal-id element should occur only once per file no matter which of the xml files are processing through.

I'm testing this now and will let you know what I find out.

THANKS!!!