7 Replies Latest reply on Sep 28, 2008 12:23 AM by BKBK

    xml post Urgent

    craig_mac Level 1
      Hi can someone please help me, i need to read a xml post but not sure how to do it..

      the xml post comes to my url in this format

      <DeliveryReport><message id="1023012301" sentdate=""
      donedate="2005/7/19 22:0:0" status="NOT_SENT" /></DeliveryReport>

      all i need to get is the message id and the status

      thanks
        • 1. Re: xml post Urgent
          Level 7
          What of the online documentation about CF's XML processing (or even string
          processing) functions have you read and tried to get working?

          Where' some code you've tried to get the relevant values out? In what way
          does the code not work?

          For starters:
          XML approach:
          http://livedocs.adobe.com/coldfusion/8/functions-pt0_21.html#3468770

          String approach:
          http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_18.html#1099887

          --
          Adam
          • 2. Re: xml post Urgent
            craig_mac Level 1
            Hi yes i have tried several things i ended up with this

            <cfset x = GetHttpRequestData().content>
            #x.DeliveryReport.message id#<br>
            #x.DeliveryReport.status#<br>

            • 3. Re: xml post Urgent
              BKBK Adobe Community Professional & MVP
              I suppose Adam means you should read up on the two approaches he mentions. Take it from here

              <!--- text content --->
              <cfsavecontent variable="x">
              <DeliveryReport><message id="1023012301" sentdate=""
              donedate="2005/7/19 22:0:0" status="NOT_SENT" /></DeliveryReport>
              </cfsavecontent>

              <!--- convert text to XML object --->
              <cfset xmlObj = xmlParse(x)>

              <!--- extract message id using Coldfusion's XML functionality --->
              <cfset msgID = xmlObj.xmlRoot["message"].XmlAttributes["id"]>
              message id = <cfoutput>#msgID#</cfoutput>

              • 4. Re: xml post Urgent
                Level 7
                > <cfset x = GetHttpRequestData().content>
                > #x.DeliveryReport.message id#<br>
                > #x.DeliveryReport.status#<br>

                And I presume that didn't work (typo in the second line aside)?

                According to the docs for getHttpRequestData():
                http://livedocs.adobe.com/coldfusion/8/functions_e-g_43.html

                the "content" key will be a string.

                So the first question is: can one take a STRING and refer to it as if it's
                a structure like you have? I get this error:

                {quote}
                You have attempted to dereference a scalar variable of type class
                java.lang.String as a structure with members.
                {quote}

                So I'm guessing "no" (actually I know so, but I'm trying to approach this
                from an POV of trying to work it out for the first time).

                So one cannot see some XML in a string and hope CF will also work out that
                you want the string to be treated as XML. You might need to convert the
                string to XML first.

                This should lead you to investigate how to do that, and I suspect that if
                you're read any of the docs I pointed you to, you'd have got at least that
                far. So I'm guessing you *didn't* bother to read those docs, so I'm kinda
                wondering whether you actually *do* want to work this out.

                But anyway, if you're prepared to try to help yourself, I'm prepared to try
                to help you with that. Read the docs I pointed you to. They are not a
                random selection, they are the ones you will need to crack this one. Read
                up on xmlParse(), and then how to refer to elements within an XML doc.
                There are examples of this in the docs.

                I'm about to go out, but will check back here in a couple of hours to see
                if you've made any progress.

                --
                Adam
                • 5. Re: xml post Urgent
                  craig_mac Level 1
                  ok thanks that works i also have another format, but i am still not sure how to access the values

                  <test>
                  <authentification>
                  <username>usrn</username>
                  <password>ese45ss</password>
                  </authentification>
                  </test>

                  so how do i go down the children to get the value?
                  • 6. Re: xml post Urgent
                    Level 7
                    > so how do i go down the children to get the value?

                    Have a look at how the xmlAttributes and xmlText are accessed in the sample
                    code here:
                    http://livedocs.adobe.com/coldfusion/8/functions_t-z_22.html

                    --
                    Adam
                    • 7. xml post Urgent
                      BKBK Adobe Community Professional & MVP
                      so how do i go down the children to get the value?

                      You thirsty in the river? It's all there, if you'd look. In fact, you could just copy and paste.