BonnieK
asked on
Problems reading XML response with Coldfusion 9 XMLParse
Hello,
I am having trouble reading an XML response. I am not sure if I can explain it well. I am using XMLParse on the filecontent.
When I do this directly from the response from the web service I am using, it seems that I am getting just one chunk of XMLText instead of each piece of information with its node label.
<cfdump var="#xmlparse(httpRespons e.filecont ent)#">
If I show the filecontent on the screen, then copy and paste it into notepad and name it something.xml, then run XML Parse, I am able to access the different nodes.
<cfdump var="#xmlparse("test.xml") #">
Below is the filecontent that I am able to create an xml document with and read successfully.
Attached are images of the two cfdump calls. I think the pictures should explain it.
I am not sure if this has to do with XMLParse or with the response data that is being returned to me.
Any help would be much appreciated. I have been trying to figure this out for two days now and am exhausted...
<?xml version="1.0" encoding="utf-8"?><soap:En velope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><E xecuteXMLR esponse xmlns="http://rossinc.com/webservices/"><ExecuteXMLResult ><method name="RS_BIN_TRANSFER"><da tabase>_CO NNECTSERVI CE</databa se> <parameters><parameter> <name>ERROR_OCCURRED</name > <value>1</value> </parameter> <parameter> <name>XML_TAGS</name> <value>1</value> </parameter> <parameter> <name>Unknown2</name> <value></value> </parameter> </parameters><tables><tabl e name="RS_SYS_MESSAGES"> <data> <row number="1"> <RS_MESSAGE_NUMBER>P_13349 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>0</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Validatin g Table IC_BIN_TRANSFER_CONTROL_VT , Reference 1</RS_MESSAGE_TEXT> <RS_SEQUENCE>1</RS_SEQUENC E> <RS_SORT_ORDER>1</RS_SORT_ ORDER> </row> <row number="2"> <RS_MESSAGE_NUMBER>P_42264 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>1</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Insuffici ent Qty Available at Bin/MH level</RS_MESSAGE_TEXT> <RS_SEQUENCE>1</RS_SEQUENC E> <RS_SORT_ORDER>2</RS_SORT_ ORDER> </row> <row number="3"> <RS_MESSAGE_NUMBER>P_02111 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>1</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Validatio n on RS_BIN_TRANSFER_CONTROL failed.</RS_MESSAGE_TEXT> <RS_SEQUENCE>1</RS_SEQUENC E> <RS_SORT_ORDER>3</RS_SORT_ ORDER> </row> <row number="4"> <RS_MESSAGE_NUMBER>P_02973 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>1</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Update Failed</RS_MESSAGE_TEXT> <RS_SEQUENCE>0</RS_SEQUENC E> <RS_SORT_ORDER>4</RS_SORT_ ORDER> </row> </data> </table> </tables></method> </ExecuteXMLResult></Execu teXMLRespo nse></soap :Body></so ap:Envelop e>
From-text-pasted-into-xml-file.PNG
From-xmlparse-of-response.PNG
I am having trouble reading an XML response. I am not sure if I can explain it well. I am using XMLParse on the filecontent.
When I do this directly from the response from the web service I am using, it seems that I am getting just one chunk of XMLText instead of each piece of information with its node label.
<cfdump var="#xmlparse(httpRespons
If I show the filecontent on the screen, then copy and paste it into notepad and name it something.xml, then run XML Parse, I am able to access the different nodes.
<cfdump var="#xmlparse("test.xml")
Below is the filecontent that I am able to create an xml document with and read successfully.
Attached are images of the two cfdump calls. I think the pictures should explain it.
I am not sure if this has to do with XMLParse or with the response data that is being returned to me.
Any help would be much appreciated. I have been trying to figure this out for two days now and am exhausted...
<?xml version="1.0" encoding="utf-8"?><soap:En
From-text-pasted-into-xml-file.PNG
From-xmlparse-of-response.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YOU. ARE. MY. HERO!!!!!!!
Now, I just wish I understood :)
This: <cfset newNode = xmlParse(node.xmlText)> worked perfectly.
It looks like you found xmlText and then parsed it. I knew the issue had something to do with the conversion of the < and > to < and > but could not get it to work. I was writing the response to an xml file and when I ran a find and replace on those character indications and changed them to < and > then I was able to parse it.
I am an XML newbie - so I will need to do some research on how this works:
2:<cfset node = doc["soap:Envelope"]["soap :Body"]["E xecuteXMLR esponse"][ "ExecuteXM LResult"]>
Anyway. There was zero chance I was going to be able to get to this point without your help. I miss the old days where I could give you points. I have been away from EE for a while. And I told myself if someone here helps me with this I will move to a premium account...so here I go!
You are amazing _agx_
Thank you for your time,
Bonnie
ToString: <?xml version="1.0" encoding="UTF-8"?> <ExecuteXMLResult xmlns="http://rossinc.com/webservices/"><method name="RS_DECR_INVENTORY_V2 "><d atabase> ;_CONNECTS ERVICE< /database& gt; <parameters><para meter> <name>ERROR_OCCURRED </name& gt; <value>1</value&g t; </parameter> <parameter> <name>XML_TAGS</n ame> <value>1</value&g t; </parameter> <parameter> <name>Unknown2</n ame> <value></value> ; </parameter> </parameters><tab les>< ;table name="RS_SYS_MESSAGES"> <data> <row number="1"> <RS_MESSAGE_NUMBER>P _10648< /RS_MESSAG E_NUMBER&g t; <RS_MESSAGE_SEVERITY> ;1</RS_ MESSAGE_SE VERITY> <RS_MESSAGE_TEXT>Inv alid Movement Code</RS_MESSAGE_TEXT&g t; <RS_SEQUENCE>0</R S_SEQUENCE > <RS_SORT_ORDER>1< /RS_SORT_O RDER> </row> <row number="2"> <RS_MESSAGE_NUMBER>P _02973< /RS_MESSAG E_NUMBER&g t; <RS_MESSAGE_SEVERITY> ;1</RS_ MESSAGE_SE VERITY> <RS_MESSAGE_TEXT>Upd ate Failed</RS_MESSAGE_TEXT > <RS_SEQUENCE>0</R S_SEQUENCE > <RS_SORT_ORDER>2< /RS_SORT_O RDER> </row> </data> </table> </tables></method > </ExecuteXMLResult>
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
XMLText: <method name="RS_DECR_INVENTORY_V2 "><databas e>_CONNECT SERVICE</d atabase> <parameters><parameter> <name>ERROR_OCCURRED</name > <value>1</value> </parameter> <parameter> <name>XML_TAGS</name> <value>1</value> </parameter> <parameter> <name>Unknown2</name> <value></value> </parameter> </parameters><tables><tabl e name="RS_SYS_MESSAGES"> <data> <row number="1"> <RS_MESSAGE_NUMBER>P_10648 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>1</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Invalid Movement Code</RS_MESSAGE_TEXT> <RS_SEQUENCE>0</RS_SEQUENC E> <RS_SORT_ORDER>1</RS_SORT_ ORDER> </row> <row number="2"> <RS_MESSAGE_NUMBER>P_02973 </RS_MESSA GE_NUMBER> <RS_MESSAGE_SEVERITY>1</RS _MESSAGE_S EVERITY> <RS_MESSAGE_TEXT>Update Failed</RS_MESSAGE_TEXT> <RS_SEQUENCE>0</RS_SEQUENC E> <RS_SORT_ORDER>2</RS_SORT_ ORDER> </row> </data> </table> </tables></method>
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Raw Value: <?xml version="1.0" encoding="UTF-8"?> <ExecuteXMLResult xmlns="http://rossinc.com/webservices/"><method name="RS_DECR_INVENTORY_V2 "><d atabase> ;_CONNECTS ERVICE< /database& gt; <parameters><para meter> <name>ERROR_OCCURRED </name& gt; <value>1</value&g t; </parameter> <parameter> <name>XML_TAGS</n ame> <value>1</value&g t; </parameter> <parameter> <name>Unknown2</n ame> <value></value> ; </parameter> </parameters><tab les>< ;table name="RS_SYS_MESSAGES"> <data> <row number="1"> <RS_MESSAGE_NUMBER>P _10648< /RS_MESSAG E_NUMBER&g t; <RS_MESSAGE_SEVERITY> ;1</RS_ MESSAGE_SE VERITY> <RS_MESSAGE_TEXT>Inv alid Movement Code</RS_MESSAGE_TEXT&g t; <RS_SEQUENCE>0</R S_SEQUENCE > <RS_SORT_ORDER>1< /RS_SORT_O RDER> </row> <row number="2"> <RS_MESSAGE_NUMBER>P _02973< /RS_MESSAG E_NUMBER&g t; <RS_MESSAGE_SEVERITY> ;1</RS_ MESSAGE_SE VERITY> <RS_MESSAGE_TEXT>Upd ate Failed</RS_MESSAGE_TEXT > <RS_SEQUENCE>0</R S_SEQUENCE > <RS_SORT_ORDER>2< /RS_SORT_O RDER> </row> </data> </table> </tables></method > </ExecuteXMLResult>
xml-parse-of-node-xmltext.PNG
Now, I just wish I understood :)
This: <cfset newNode = xmlParse(node.xmlText)> worked perfectly.
It looks like you found xmlText and then parsed it. I knew the issue had something to do with the conversion of the < and > to < and > but could not get it to work. I was writing the response to an xml file and when I ran a find and replace on those character indications and changed them to < and > then I was able to parse it.
I am an XML newbie - so I will need to do some research on how this works:
2:<cfset node = doc["soap:Envelope"]["soap
Anyway. There was zero chance I was going to be able to get to this point without your help. I miss the old days where I could give you points. I have been away from EE for a while. And I told myself if someone here helps me with this I will move to a premium account...so here I go!
You are amazing _agx_
Thank you for your time,
Bonnie
ToString: <?xml version="1.0" encoding="UTF-8"?> <ExecuteXMLResult xmlns="http://rossinc.com/webservices/"><method name="RS_DECR_INVENTORY_V2
--------------------------
XMLText: <method name="RS_DECR_INVENTORY_V2
--------------------------
Raw Value: <?xml version="1.0" encoding="UTF-8"?> <ExecuteXMLResult xmlns="http://rossinc.com/webservices/"><method name="RS_DECR_INVENTORY_V2
xml-parse-of-node-xmltext.PNG
ASKER
Thank you so much.
ASKER
Looks like we still can give points :)
Very glad I could help :)
For the most part, XML nodes are just like nested CF structures you can access with the right combination of key names. The "name" of each node in the xml, becomes the name of a structure:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope ...> <=== (Name "soap:Envelope" becomes the root structure)
- <soap:Body> <=== (Name "soap:Body" becomes a child structure)
--- <ExecuteXMLResponse> <=== (Name "ExecuteXMLResponse" becomes a child structure)
... etc...
Ignoring the "soap:" prefix for a moment, the xmlParse result will be similar to creating nested structures like this with CFML:
<cfset myStruct.Envelope.body.Exe cuteXMLRes ponse.Exec uteXMLResu lt = "more objects here">
<cfdump var="#myStruct#">
To get a specific node, use regular dot notation or structure notation
#myStruct.Envelope#
#myStruct.Envelope.body#
#myStruct.Envelope.body.Ex ecuteXMLRe sponse#
.... OR ....
#myStruct["Envelope"]#
#myStruct["Envelope"]["bod y"]#
#myStruct["Envelope"]["bod y"]["Execu teXMLRespo nse"]#
So getting back to the xmlParse, it basically converts the input string into a bunch of nested structures that you see in the dump.
<cfset doc = xmlparse(trim(filecontent) )>
<cfdump var="#doc#">
Since the some of the key names contains invalid characters, like colon ":", you must use structure notation to access the nodes. To grab the top level node "<soap:Envelope>", use the key name "soap:Envelope" (do not include the < and >)
<cfset envelopeNode = doc['soap:Envelope']>
<cfdump var="#envelopeNode#">
To get the next level down, </soap:Body>, just add the child key "soap:Body"
<cfset bodyNode = doc['soap:Envelope']['soap :Body']>
<cfdump var="#bodyNode#">
... and so on.
It looks like you found xmlText and then parsed it.Yep. Since xmlParse did not convert that particular text, my guess is the sender is deliberately escaping it somehow to prevent it from being interpreted. For example, they might be marking it as CDATA (character data or character literal). So the solution is to grab the node's text and xmlparse it separately.
I am an XML newbie - so I will need to do some research on how this works:
2:<cfset node = doc["soap:Envelope"]["soap:Body"]["E xecuteXMLR esponse"][ "ExecuteXM LResult"]>
For the most part, XML nodes are just like nested CF structures you can access with the right combination of key names. The "name" of each node in the xml, becomes the name of a structure:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope ...> <=== (Name "soap:Envelope" becomes the root structure)
- <soap:Body> <=== (Name "soap:Body" becomes a child structure)
--- <ExecuteXMLResponse> <=== (Name "ExecuteXMLResponse" becomes a child structure)
... etc...
Ignoring the "soap:" prefix for a moment, the xmlParse result will be similar to creating nested structures like this with CFML:
<cfset myStruct.Envelope.body.Exe
<cfdump var="#myStruct#">
To get a specific node, use regular dot notation or structure notation
#myStruct.Envelope#
#myStruct.Envelope.body#
#myStruct.Envelope.body.Ex
.... OR ....
#myStruct["Envelope"]#
#myStruct["Envelope"]["bod
#myStruct["Envelope"]["bod
So getting back to the xmlParse, it basically converts the input string into a bunch of nested structures that you see in the dump.
<cfset doc = xmlparse(trim(filecontent)
<cfdump var="#doc#">
Since the some of the key names contains invalid characters, like colon ":", you must use structure notation to access the nodes. To grab the top level node "<soap:Envelope>", use the key name "soap:Envelope" (do not include the < and >)
<cfset envelopeNode = doc['soap:Envelope']>
<cfdump var="#envelopeNode#">
To get the next level down, </soap:Body>, just add the child key "soap:Body"
<cfset bodyNode = doc['soap:Envelope']['soap
<cfdump var="#bodyNode#">
... and so on.
ASKER
:1:206: cvc-elt.1: Cannot find the declaration of element 'soap:Envelope'.