Skip to main content
Inspiring
August 1, 2011
Answered

XML Problem

  • August 1, 2011
  • 3 replies
  • 2726 views

A partner firm needs to pass me some xml information and I need to get that info and run queries with the UserID in the passed info.


They pass me this xml


<Request>

<Header>

<UserId>phutch</UserId>

<Token>08012011T1149034</Token>

</Header>

</Request>


I am trying to retrieve the UserId from the xml file using <cfdump var="#GetHttpRequestData()#">


I was hoping that I could get the xml info from the GetHttpRequestData() tag but I get an error message


"The markup in the document following the root element must be well-formed.

Nested exception: The markup in the document following the root element must be  well-formed."


I think the error might be because this line of code is not at the beginning of the xml passed to me.


<?xml version="1.0" encoding="iso-8859-1"?>  or 


<?xml version="1.0" encoding="utf-8"?>


Anyway.  Does anyone have any ideas on how I could extract the UserId from the above xml?

    This topic has been closed for replies.
    Correct answer Avatar

    Take a look at this post from Ben Nadel regarding "Maintaining Sessions Across Multiple ColdFusion CFHttp Requests" it should get you what you need.

    3 replies

    Participating Frequently
    August 4, 2011

    One issue I have encountered in the past with Webservice XML is that sometimes whitespace ends up in your XML and causes the XML functions like XMLParse to fail.

    Using the TRIM function helps get around this, like the following:

    <cfset XmlObject = XmlParse(Trim(XmlData))>

    Also you can use the CFWDDX tag to transfer the XML into a ColdFusion struct variable, this is a very useful tag.

    Michael G. Workman

    michael.g.workman@gmail.com

    weezerboyAuthor
    Inspiring
    August 4, 2011

    My big problem now is that my partner firm sends me a file to validate, after I validate it , I need to send them back an xml response.

    I've done all of this and the response is getting back to my partners server

    BUT now they tell me that I need to keep the session they send to me alive and send my response back to them with the same session.

    Any thoughts on that.

    Patrick Hutchinson

    AvatarCorrect answer
    Participating Frequently
    August 4, 2011

    Take a look at this post from Ben Nadel regarding "Maintaining Sessions Across Multiple ColdFusion CFHttp Requests" it should get you what you need.

    Participating Frequently
    August 1, 2011

    If its in the body of an http post you can try this:

    <cfset XmlData = XmlParse(ToString(getHTTPRequestData().content))>


    <cfif StructKeyExists(XmlData.Request.Header.UserID, "xmlText")>
        <cfset UserID = XmlData.Request.Header.UserID.XmlText>
    </cfif>

    weezerboyAuthor
    Inspiring
    August 2, 2011

    The xml is passed with a  RESTful (Representational State Transfer) web service over HTTP protocol doing XML communication. I need  to post the request as XML stream, by setting the content type as "text/xml"

    Heres the code I have now

    <cfif cgi.user_agent contains "Mozilla">
         <cfheader name="Content-Type" value="text/xml">
    <cfelse>
         <cfheader name="Content-Type" value="application/rss+xml">
    </cfif>
      <cfset XmlData = XmlParse(ToString(getHTTPRequestData().content))>
    <cfif StructKeyExists(XmlData.Request.Header.UserID, "xmlText")>a
      <cfset UserID = XmlData.Request.Header.UserID.XmlText>
    </cfif>

    I now get this error

    The XML page cannot be displayed

    Cannot view XML input using style sheet.  Please correct the error and then click the Refresh button, or try  again later.


    Incorrect syntax was used in a comment.  Error processing resource  'http://symmetrypartners.temppublish.com/envestnet_do_log...

     <!-- " ---></TD></TD></TD></TH></TH></TH></TR></TR></TR></TA...
    Owainnorth
    Inspiring
    August 2, 2011

    So you're saying it's basically an HTTP POST to your page? In which case I'd start by just getting the getHTTPRequestData() content and dumping that out to see what you have. Don't bother with xmlParse() or anything until you know you have a page with usable ColdFusion content you can then work with.

    Owainnorth
    Inspiring
    August 1, 2011

    How are they passing the Xml to your page?

    weezerboyAuthor
    Inspiring
    August 2, 2011

    The xml is passed with a  RESTful (Representational State Transfer) web service over HTTP protocol doing XML communication. I need  to post the request as XML stream, by setting the content type as "text/xml"

    Heres the code I have now

    <cfif cgi.user_agent contains "Mozilla">
        <cfheader name="Content-Type" value="text/xml">
    <cfelse>
        <cfheader name="Content-Type" value="application/rss+xml">
    </cfif>
    <cfset XmlData = XmlParse(ToString(getHTTPRequestData().content))>
    <cfif StructKeyExists(XmlData.Request.Header.UserID, "xmlText")>a
    <cfset UserID = XmlData.Request.Header.UserID.XmlText>
    </cfif>

    I now get this error

    The XML page cannot be displayed

    Cannot view XML input using style sheet.  Please correct the error and then click the Refresh button, or try  again later.


    Incorrect syntax was used in a comment.  Error processing resource  'http://symmetrypartners.temppublish.com/envestnet_do_log...

     <!-- " ---></TD></TD></TD></TH></TH></TH></TR></TR></TR></TA...