Error Converting XML to CDT using torecord() function.

Certified Senior Developer

I am getting the below-mentioned error while converting xml to cdt using torecord() function. 

Does any one know what is the root cause of this error ?? or Let me know alternatives of converting XML to CDT ?

Thanks

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Peter Lewis

    Hi Peter,

    Thanks for your reply.  Yes, SearchInquiryResponse is the name of my CDT. I'll try the trial and error way, for now, to find out the issue.

  • 0
    Certified Senior Developer
    in reply to Peter Lewis

    , There is a special character ampersand(&) in the XML which is causing this error.

    Can you please let me know how to handle this scenario as my XML might contain special characters as well ?

    Is there any way to handle it and convert them to XML escaped format? 

    XML escaped characters

    Special character escaped form gets replaced by
    Ampersand & &
    Less-than &lt; <
    Greater-than &gt; >
    Quotes &quot; "
    Apostrophe &apos; '
  • 0
    Certified Lead Developer
    in reply to Akash Chalamcharla

    Where is the XML getting generated?  The text being passed into the XML's data will need to be sanitized so that parsing it later doesn't break (similar things happen, for instance, if these unsanitized characters are passed into the MS Word from Template smart service).  The sanitization rule I always use looks something like this:

    a!localVariables(
      local!characters: {
        "&",
        ">",
        "<",
        """", /* quote */
        "'", /* apostrophe */
        char(10),
        char(13)
      }, /* the ordering of these is important. */
    
      local!replacements: {
        tohtml("&"),
        tohtml(">"),
        tohtml("<"),
        "\&\quot;",
        "\&\apos;",  -- note: backslashes added here just to post on Community
        "\&\#10;",
        ""
      },
    
      reduce(
        fn!substitute,
        trim(ri!input),
        a!forEach(
          local!characters,
          {
            fv!item,
            local!replacements[fv!index]
          }
        )
      )
    )