Forum Discussion

dwhite's avatar
dwhite
Employee
8 years ago

Validate XML in Binary Form Without Parsing

If you’re having problems with XML validation going in or out of XML (formatter/parser) or if you wish to validate a binary XML without parsing it so save execution time you can use the XSLT snap to do this validation.

XSLT snap takes a binary input and has a binary output and has an xsd setting available to use for validation against the input data to the snap. You can utilize this function to do your validation without modifying the input XML data.

You can write a simple xslt file such as this to essentially pass through the XML data without modifying the structure. This is valid in our XSLT snap and when paired with an XSD essentially converts XSLT snap into a binary xml validator.

Sample XSLT that can be used to perform pass-through functions for any structure:

<xsl:stylesheet version=“1.0” xmlns:xsl=“XSLT Namespace”>
<xsl:output method=“xml” version=“1.0” encoding=“UTF-8” indent=“yes”/>
<xsl:template match=“/”>
<xsl:copy-of select=“*”/>
</xsl:template>
</xsl:stylesheet>

  • djsiegel's avatar
    djsiegel
    Former Employee

    Hi Mohit!
    What you might try is passing that JSON over to a mapper, and using the mapper to do what you want.
    Turn off pass through in the mapper and use an expression language statement to convert everything to a string like this:

    $.mapValues(x=>x == null ? "" : x.toString())
    

    This will essentially set everything to a string, even an empty string.
    Here’s what my mapper looks like to do this:

    Hope that gets you closer!
    – David

    • mohit3's avatar
      mohit3
      New Contributor

      @djsiegel I am not using the pass through. I am just mapping the fields in mapper snap and then sending it to Json formatter snap to generate the Json but it is only showing single quotation mark for empty values.

      I tried your expression as well but it is also not working.

  • Mohit, this is just an odd bug in the Designer’s viewer for JSON preview data. If you actually save the output of the JSON Formatter to a file using a File Writer, you’ll see that the empty string is a pair of double quotes as you expect.

    • djsiegel's avatar
      djsiegel
      Former Employee

      Can confirm, Patrick - I happened to just be building an example to test myself.
      When I download it, I do see the doublequotes.
      Mohit - here’s my example, with both the input and output. Hope that helps.

      CommunityExampleJSON.zip (4.3 KB)

      • ptaylor's avatar
        ptaylor
        Employee

        David, I downloaded and validated your pipeline. Even with the Mapper, the preview dialog for the JSON Formatter’s output shows the same problem with displaying a single double quote instead of two double quotes:

        Your Mapper doesn’t change these values since they are already strings.