9 Replies Latest reply on May 24, 2007 9:33 AM by Balddog

    XML set to variable

    Balddog
      I'm able to set a variable based on an xml response. When I output it, it appears fine. When I update my database with the variable, it's showing extra information. Why isn't it showing up in the output? I'm using the same #variable.resultcode#, etc.

      Example:
      Result Code: Error
      Code: E00012
      Text: You have submitted a duplicate ...

      Update Query:
      set ARBresultcode = '<?xml version="1.0" encoding="UTF-8"?> <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Error</resultCode>', ARBcode = '<?xml version="1.0" encoding="UTF-8"?> <code xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">E00012</code>', ARBtext = '<?xml version="1.0" encoding="UTF-8"?> <text xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">You have submitted a duplicate of Subscription 1395221. A duplicate subscription will not be created.</text>'
        • 1. Re: XML set to variable
          Level 7
          > extra
          > information

          What "extra information"?

          --
          Adam
          • 2. Re: XML set to variable
            Abinidi Level 1
            Are you actually inputting in your table:

            <?xml version="1.0" encoding="UTF-8"?> <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Error</resultCode>', ARBcode = '<?xml version="1.0" encoding="UTF-8"?> <code xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">E00012</code>', ARBtext = '<?xml version="1.0" encoding="UTF-8"?> <text xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">You have submitted a duplicate of Subscription 1395221. A duplicate subscription will not be created.</text>'


            If so , it will interpret it wrong. I would use ampersands and such to convert the symbols.
            • 3. XML set to variable
              Balddog Level 1
              When I output the resultCode, it just shows "Success."

              When I try to insert the result into the database, it tries to input all of this rather than just the resultCode "Success." It's as if it isn't parsing it. It appears to be in the output though. I don't want it to input all of that, only the result, "Success."

              <?xml version="1.0" encoding="UTF-8"?> <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Success</resultCode>',
              • 4. Re: XML set to variable
                BKBK Adobe Community Professional & MVP
                > I don't want it to input all of that, only the result, "Success."
                Then you should not be doing

                SET status = '<?xml version="1.0" encoding="UTF-8"?> <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Success</resultCode>'

                You should instead do something like

                <cfxml variable="statusXML">
                <?xml version="1.0" encoding="UTF-8"?>
                <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
                Success
                </resultCode>
                </cfxml>
                <cfset XmlStatus = statusXML.XmlRoot.XmlText>


                Then, in the update query, you would do

                SET status = '#trim(XmlStatus)#'

                The cfoutput tag has been designed to ignore tags, including your own custom ones. That is why you get just the word Success when you cfoutput the string

                <?xml version="1.0" encoding="UTF-8"?> <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">Success</resultCode>




                • 5. Re: XML set to variable
                  Level 7
                  > The cfoutput tag has been designed to ignore tags, including your own custom
                  > ones. That is why you get just the word Success when you cfoutput the
                  > string

                  <cfoutput> "ignores" everything that's not CF (tag or otherwise).

                  It's the BROWSER that does not render the tags, because browser DON'T
                  render tags. When have you ever seen a tag render on the browser screen?
                  Some tags - by agreement of the browser vendors and the W3C - describe how
                  the output of text WITHIN tags should get displayed (<em> might suggest
                  italicisation, for example). By design, other tags are ignored.

                  It's nowt to do with CF any more than <em> causing text to be italicised in
                  the browser has anything to do with CF.

                  --
                  Adam
                  • 6. Re: XML set to variable
                    BKBK Adobe Community Professional & MVP
                    Rboudwin expects cfoutput to extract Xmltext, presumably by parsing the elements/tags. My point is that cfoutput doesn't do that. I didn't include the browser. So my point may seem self-contradictory, as it would suggest that the browser displayed the word Success because cfoutput removed the tags. That is of course not so.

                    <cfoutput> "ignores" everything that's not CF (tag or otherwise).
                    It's the BROWSER that does not render the tags, because browser DON'T
                    render tags.


                    Your phrasing is a useful addition and sheds more light on the matter. The two statements are not mutually exclusive, though. Coldfusion sends the tags that cfoutput ignores to the browser. The browser may then render or not render them. In this case, it doesn't.



                    • 7. Re: XML set to variable
                      Balddog Level 1
                      I'm sorry for being so dense. I don't see how to do the following you gave me since it's what is returned from another site. I did use trim in the variable, but it still kept the entire string.

                      <cfxml variable="statusXML">
                      <?xml version="1.0" encoding="UTF-8"?>
                      <resultCode xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
                      Success
                      </resultCode>
                      </cfxml>
                      • 8. Re: XML set to variable
                        BKBK Adobe Community Professional & MVP
                        > I did use trim in the variable, but it still kept the entire string.

                        That cannot be. Did you apply both

                        <cfset XmlStatus = statusXML.XmlRoot.XmlText>

                        and

                        SET status = '#trim(XmlStatus)#'?


                        • 9. Re: XML set to variable
                          Balddog Level 1
                          Hot ziggety, it worked! I had a typo in it. Thank you! Thank you! Thank you!

                          I want to understand xml better. It doesn't seem complex. I just don't have a clear handle on it.