ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

XML-INTO and boolean variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML-INTO and boolean variable

    I use XML-INTO for parsing
    Code:
    <val>true</val>
    element into structure

    Code:
    dcl-ds q Qualified;
      val ind;
    end-ds;
    In g.val field I found "t" value.

    It seems XML-INTO parsing <val> element as a string.

    Is any way to force conversion to IND type?

  • #2
    Simple answer - No.

    Unlike json XML does not have a predefined meaning for the string "true". So the parser does not offer a translation option. Just change the definition to char(5) - I'm assuming "false" is also an option - and then test/set an indicator yourself.

    Comment


    • #3
      Originally posted by JonBoy View Post
      Simple answer - No.

      Unlike json XML does not have a predefined meaning for the string "true". So the parser does not offer a translation option. Just change the definition to char(5) - I'm assuming "false" is also an option - and then test/set an indicator yourself.
      ... at least if you working with XML-INTO and not with (embedded) SQL!
      In the following example true/false in an XML-Document is converted into Boolean;

      Code:
      Select x.*, Integer(MyBoolBoolean) as MyBoolInteger
        from XMLTABLE('/rowset/row'
               Passing XMLParse(Document
                          '<rowset>
                              <row><MYID>1</MYID><MYBOOLEAN1>false</MYBOOLEAN1><MYBOOLEAN2>false</MYBOOLEAN2></row>
                              <row><MYID>3</MYID><MYBOOLEAN1>true</MYBOOLEAN1><MYBOOLEAN2>true</MYBOOLEAN2></row>
                          </rowset>')
               Columns MyId Integer,
                       MyBoolVarChar     VarChar(5)                Path 'MYBOOLEAN1',
                       MyBoolVarGraphic  VarGraphic(5) CCSID 1200  Path 'MYBOOLEAN1',
                       MyBoolBoolean     Boolean                   Path 'MYBOOLEAN1') x;  ​

      Comment


      • #4
        So, this means that XML-INTO has no boolean(true,false)->ind translation implemented .

        Comment


        • #5
          Correct - XML-INTO does not look at the XSD specification for the file and so has no idea that what it sees as a simple character string is implementing a boolean. Remember that with XSDs you can basically create any data type you want - so there's really no more reason for it to handle this than any other "made up" data type.

          Comment


          • #6
            XML-INTO sees true/false in source data and boolean as target variable. In fact, IBM may have doubts about translation when building a function XML-INTO

            Comment


            • #7
              XML-INTO does exactly what it is supposed to do and does it, in my opinion, correctly. As I noted - it does not process the XSD and so has no way of knowing that the word "true" should be mapped to a boolean. Just process it as character there is no advantage to being able to treeat it as an indicator.

              Comment


              • #8
                FWIW -- if you don't like the way XML-INTO works, you can write a DATA-INTO handler to process XML, and it can convert "true" to *ON and "false" to *OFF if you want it to.

                Comment

                Working...
                X