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 :)

32 comments:

  1. Dude,

    You just saved me a boat load of work. We have a massive XSD with about 1500 elements and many complex types => xml views. And I had to move a few elements, I was afraid to re import the XSD as that would require mapping all the elements again. This post saved our lives. Thank you SOOOO MUCH. YOU ROCK!!

    ReplyDelete
  2. if I have the two name spaces which one i have to take?

    ReplyDelete
    Replies
    1. Well, I did not have any chance to test such a scenario. Can you try both and share the result?

      Delete
  3. I tried working on this, but the Synchronize XML definition option is not available for me. Do i need to re-import the xsd file or keep it open? Also after changing in xsd, when i tried to save it , it mentioned that there are no changes detected.Help me out!!!

    ReplyDelete
  4. Hi,
    could you help me in how to add new field(input&ouput) in the xml parser apart from default field(DataInput) ?
    my requirement is xml data is coming from Oracle table.
    here there is one field xml_text having xml content and app_id having application ids related to xml content. now i want to validate the xml content thru xml parser trans then i want to separate the xml content along with related app_id value based on valid or invalid.
    in the normal procedure i can track only xml content(by enabling the Route invalid payload through data flow option) but how could i also link app_id field from xml parser to next trans/target.

    Much appriciate on your quick help.

    ReplyDelete
    Replies
    1. I'd need you to be more specific. Please ask the question on stackoverflow.com - it's far more convenient. You can add more details, screenshots, edit if needed. Plus, there's a bunch of other experienced Informatica developers that are always eager to help.

      Delete
  5. This article has helped a lot!! thank you. A question for you. If we use a reusable transformation with this midstream parser and use the same transformation in multiple mappings would the transformation be cached when these mappings are triggered from one workflow with multiple sessions running each mapping?

    ReplyDelete
    Replies
    1. Glad to know it's helpful - thanks!
      This question is related to how IS actually executes a job. I won't be able to provide full details. However at run time IS creates a in-memory copy of workflow and mappings and as far as I know it's clever enough to create one mapping instance even though multiple sessions use it.

      Delete
  6. Hi,

    It's nearly impossible to find a real tip just to add a fracking field in XML generator... thanks 10^9 times, you saved my day !

    ReplyDelete
    Replies
    1. Thanks for the comment! It's really rewarding to know it helped someone :)

      Delete
  7. How to join two group from XMl parser to Target?Please help me ...Thanks a lot in advance!!

    ReplyDelete
  8. How to join two group from XMl parser to Target?Please help me ...Thanks a lot in advance!!

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This doesn't work when more than one namespaces is available? In that case synchronize creates a target with just that namespace. (We have a rather old version (9.1) where no XML Parser is used but just the XML target. The XML View though is similar so I expect this is not the reason it doesn't work).

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. HI, My xml file fields are changes depend on data. If any one of particular column has null in source side xml file don't have that field .How to load the this type of data.

    ReplyDelete
    Replies
    1. XML Parser handles that for you. There's nothing you need to do except declaring all POSSIBLE columns.

      Delete
  13. Thank you quick response.Let me try.

    ReplyDelete
  14. I got the below error while import the xsd defination.
    Warning: the xml defination is too large and will be considered invalid.

    ReplyDelete
    Replies
    1. That seems to be a different issue. You may try to google for this error, check Informatica Knowledgebase, look for some help on forums (I'd recommend stackoverflow.com). Or share the XSD so I could check.

      Delete
  15. I got the below error while import the xsd defination.
    Warning: the xml defination is too large and will be considered invalid.

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Please note that this is not an XSD. This is a sample XML. Please:
      1. Learn how to reply, instead of creating new thread each time
      2. Use some code-sharing site instead of pasting code into comments
      3. Use some dedicated forum and knowledgebase to seek help

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Sure, Next time i will follow.



      My question is related to load the xml file into target table,

      For example my file has same field multiple times.
      ex:
      {dept_data}
      {emp_no}11{emp_no}
      {name}xx{name}
      {department}
      {deptn_no}10{deptno_no}
      {loc}abcd{loc}
      {department}
      {department}
      {deptn_no}20{deptno_no}
      {loc}xyz{loc}
      {department}
      {dept_data}

      Note:Some times {department} tags may be increaded, We don't no how many times it will.

      For this type of data, How we can configure the XML parsor transformation.


      Can you please tell me how use the code share.

      In code share site my url looks like: https://codeshare.io/5Q8eQe

      Delete
  18. This comment has been removed by the author.

    ReplyDelete
  19. REALLY .. YOU HELP ALOTTTTT... THANK YOU VERY MUCH!!1

    ReplyDelete
  20. Awesome..works like charm.. thanks a lot..

    ReplyDelete
  21. This page is a blessing..Thanks a ton :)

    ReplyDelete
  22. Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn't show up. Grrrr... well I'm not writing all that over again. Anyhow, just wanted to say wonderful blog!

    ReplyDelete