Skip to main content

I have several XML documents with different formats, so I can’t use XML mapping. I have been able to do some manipulations with a mixture of XSLT and scripts to add to the message header.

What I need to do now is remove some parts of the XML tree based on some logic that’s not possible in XSLT alone. 

Has anyone tried this or has an example?

Unfortunately, if I understand your question correctly, this isn’t something you can do with simple operations inside of a Script connector. 

 

The best way to manipulate XML structures as a whole is via the XML Map connector, which allows you to traverse over one document model and build up another. It’s easy to skip whole sections of a tree here or overwrite individual elements, but as you point out, this relies on some uniformity in the output XML format - you couldn’t simply exclude the node at /Items/Record/ElementName without mapping everything else out. 

 

There are xml operations in ArcScript that can be used for searching a document: 

 

CData Arc - xmlDOMGet | Version 23.0.8517

CData Arc - xmlDOMSearch | Version 23.0.8517

 

But these are parsers; they don’t hold the whole document model in memory and let you cut out certain nodes.

 

Unfortunately, this really leaves just two options:

  1. If you’re talking about a finite number of XML documents, I would suggest using more than one XML Map to adjust each one - you can use the Branch connector to figure out what XML format that you’re mapping against, and then converge all of the modifications back into the same flow later.
  2. You can perform string manipulation on the content of the file body in a more generic manner - the regexreplace formatter will allow you to perform a pattern match on the chunk of XML that you wish to excise: 

    CData Arc - String Formatters | Version 23.0.8517

    This, however, is a lot more blunt of an approach, and relies on the pattern match capturing the elements to be replaced instead of XPath subtrees

Thanks for the reply! For the situation I was in I was able to put a list of IDs in a message header, e.g. a,b,c and in my XML formatter add some logic to the for loop conditional that checked the value of the XPath against that list. A bit clunky but it did work 😀.


Reply