Skip to Content

PI 7.3 not reading value inside Parent node that has child nodes

Hello Experts,

Below is a part of XML from source system and trying to map the parent tag value (Comments) to a field in target XML. But PI is passing a blank value even when there is a value present.

Part of Source XML: Value (highlighted in blue) under Comments tag needs to be mapped to a tag in target XML.


<Comments>

Comments will come here from source system and need to be mapped to a target

Test.pdf"> https://url@url.com//url@url.com</URL></Attachment>

<Attachment><URL name="TestXLS.xlsx">https://url@url.com//url@url.com</URL></Attachment>

</Comments>

Please let me know how this can be achieved.

Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jul 18, 2016 at 09:46 PM

    Hello Surajkumar,

    In ESR, elements in data type definition can either have data type assigned to them, or sub-elements, but not both at the same time. In the given example, an element 'Comments' already has sub-element ('Attachment'), thus it cannot be assigned a data type and cannot be assigned a text value. In order to resolve this issue, you shall review data type definition and:

    • Introduce additional element as a sub-element of 'Comments' - for example, 'Comment', that will not have any subsequent child elements and will be assigned the required text value, or
    • Bring the element 'Attachment' one level up so that it becomes sibling element for 'Comments' - when done so, the element 'Comments' will not have any sub-elements and can be assigned data type and corresponding required value.

    Regards,

    Vadim

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 19, 2016 at 12:39 AM

    Hi Surajkumar!

    It seems that you have element of mixed complex type in your XML. As Vadim has already mentioned above you can't use standard graphical mapping in this case. If you can't avoid using this type of element in source XML by any way you should go for XSL transformation.

    Source XML:

    <?xml version="1.0" encoding="UTF-8"?>

    <ns1:MT_Mixed xmlns:ns1="urn://test_ns">

    <Comments>Comments will come here from source system and need to be mapped to a target

    <Attachment>

    Test.pdf"> https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    <Attachment>

    <URL name="TestXLS.xlsx">https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    </Comments>

    <Comments>Another comment

    <Attachment>

    Test2.pdf"> https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    <Attachment>

    <URL name="TestXLS2.xlsx">https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    </Comments>

    </ns1:MT_Mixed>

    XSL transformation:

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:ns1="urn://test_ns">

    <xsl:template match="/">

    <ns1:MT_Result>

    <xsl:apply-templates select="//Comments"/>

    </ns1:MT_Result>

    </xsl:template>

    <xsl:template match="Comments">

    <Comments>

    <Comment> <xsl:value-of select="text()"/> </Comment>

    <xsl:copy-of select="./* except(child::text())"/>

    </Comments>

    </xsl:template>

    </xsl:stylesheet>

    Result XML:

    <?xml version='1.0' ?>

    <ns1:MT_Result xmlns:ns1="urn://test_ns">

    <Comments>

    <Comment>Comments will come here from source system and need to be mapped to a target</Comment>

    <Attachment>

    Test.pdf"> https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    <Attachment>

    <URL name="TestXLS.xlsx">https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    </Comments>

    <Comments>

    <Comment>Another comment</Comment>

    <Attachment>

    Test2.pdf"> https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    <Attachment>

    <URL name="TestXLS2.xlsx">https://url@url.com//url@url.com//url@url.com//url@url.com</URL>

    </Attachment>

    </Comments>

    </ns1:MT_Result>

    Regards, Evgeniy.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Surajkumar!

      Ok, try this:

      <?xml version="1.0" encoding="utf-8"?>

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:output method="xml" indent="yes"/>

      <xsl:template match="@* | node()">

      <xsl:copy>

      <xsl:apply-templates select="@* | node()"/>

      </xsl:copy>

      </xsl:template>

      <xsl:template match="Comments">

      <Comments>

      <Comment> <xsl:value-of select="text()"/> </Comment>

      <xsl:copy-of select="./*[not(self::text())]"/>

      </Comments>

      </xsl:template>

      </xsl:stylesheet>

      Or in your case you even can use it like this:

      <xsl:template match="Comments">

      <Comments>

      <Comment> <xsl:value-of select="text()"/> </Comment>

      <xsl:copy-of select="Attachment"/>

      </Comments>

      </xsl:template>

      Regards, Evgeniy

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.