Friday, March 29, 2013

Adding a port to an existing XML PARSER

How to add a port to an existing XML PARSER transformation? 


Usually they say:
- go to XML Editor
- create XSD
- edit the file in some external editor
- reimport the file creating a new XML Parser Transformation.

This works well, with just one little disadvantage: you loose all links. It's ok if you've got five fields. But can be a real headache if the XML structure is complex.

So lets rephrase the question:

How to add a port to an existing XML PARSER transformation without loosing all the existing links?

You begin with the same steps:

  • go to XML Editor:
    • edit the XML PARSER transformation 
    • go to "Midstream XML Parser" tab
    • click the "XML Editor" button
This should bring up the XML editor:
  • create XSD file
    • choose View XML Metadata as XML/DTD/XSD (indicated above) to bring up the following screen
    • Clicking on the namespace should bring up the file in editor (e.g. <noNamespace>)
  • edit the file in some external editor and add the required port, e.g.:
<xsd:attribute name="NewTestPort" type="xsd:string">
</xsd:attribute>

Now, go back to the mapping, right-click the existing XML PARSER and choose "Synchronize XML Definition" and point the new XSD:


Voila! Job done.

Great! But the port is still not there... Now what?

How to add a port after XML Definition has been synchronized?

First, let's take a look into XML Editor. The NewTestPort can be found in the Navigator (the left side), but it is not visible in XML View (the right side):

Right clicking it on the Navigator window (the left side, where it is visible) shows the "Show XPath Navigator" command. It does bring the XPath Navigator indeed:
The problem is that you can't drag&drop the port to the view on the right. You need to bring up the XPat Navigator but from the right pane, focusing on the appropriate branch in the XML View:

This will bring up the same XPath Navigato window, but this time allowing you to drag&drop the new added column. Now after choosing "Apply Changes" forom "File" menu (or simply clicking Ctrl+S) and closing the XML Editor, the newly added NewTestPort should be visible in the transformation:

And - most importantly - no existing links are missing! Voila! Job done. This time it's really done :)