Skip to main content
Known Participant
October 6, 2010
Answered

xmlsearch soap body

  • October 6, 2010
  • 1 reply
  • 1846 views

Hi,

When I try to do xmlsearch on the soap body, I got this error message: "An error occured while Searching an XML document. Prefix must resolve to a namespace:".  Basically I need to pull out MsgText and MsgLevel values for error checking and verifying.  Thanks

Here is the SOAP/XML structure

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

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     <soap:Body>

          <UpdateObjectResponse xmlns="http://website.com/">

               <UpdateObjectResult>

                    <xs:schema id="Test" xmlns=""  xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"  xmlns:xs="http://www.w3.org/2001/XMLSchema">

                       <xs:element msdata:IsDataSet="true" msdata:UseCurrentLocale="true" name="Test">

                              <xs:complexType>

                                   <xs:choice maxOccurs="unbounded" minOccurs="0">

                                        <xs:element name="Messages">

                                             <xs:complexType>

                                                  <xs:sequence>

                                                       <xs:element minOccurs="0" name="MsgText" type="xs:string"/>

                                                       <xs:element minOccurs="0" name="MsgLevel" type="xs:string"/>

                                                  </xs:sequence>

                                             </xs:complexType>

                                        </xs:element>

                                   </xs:choice>

                              </xs:complexType>

                         </xs:element>

                    </xs:schema>

                    <diffgr:diffgram  xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"  xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

                         <Test xmlns="">

                              <Messages diffgr:hasChanges="inserted" diffgr:id="Messages1" msdata:rowOrder="0">

                                   <MsgText> An Error Occurred Creating Transaction was rolled back</MsgText>

                                   <MsgLevel>100</MsgLevel>

                               </Messages>  

                         </Test>

                    </diffgr:diffgram>                                     

               <UpdateObjectResult>   

          </UpdateObjectResponse>

     </soap:Body>

</soap:Envelope>

    This topic has been closed for replies.
    Correct answer StevenErat

    First, notice the UpdateObjectResult is not closed so the xml is not well formed.

                        </diffgr:diffgram>                                     

                  <UpdateObjectResult>   

              </UpdateObjectResponse>

         </soap:Body>

    </soap:Envelope>

    Once that was fixed, the document was searchable without any problems.  Note that you must also remove the xml declaration from the xml string before passing it to xmlparse().

    <cfsavecontent variable="xmlstring">
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         ...{snip}
    </soap:Envelope>
    </cfsavecontent>

    <cfset messages = xmlSearch(xmlparse(xmlstring),"//Messages")>
    <cfoutput>
        Message Text: #messages[1].MsgText.XmlText#<br/>
        Message Level: #messages[1].MsgLevel.XmlText#
    </cfoutput>

    1 reply

    StevenEratCorrect answer
    Inspiring
    October 6, 2010

    First, notice the UpdateObjectResult is not closed so the xml is not well formed.

                        </diffgr:diffgram>                                     

                  <UpdateObjectResult>   

              </UpdateObjectResponse>

         </soap:Body>

    </soap:Envelope>

    Once that was fixed, the document was searchable without any problems.  Note that you must also remove the xml declaration from the xml string before passing it to xmlparse().

    <cfsavecontent variable="xmlstring">
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         ...{snip}
    </soap:Envelope>
    </cfsavecontent>

    <cfset messages = xmlSearch(xmlparse(xmlstring),"//Messages")>
    <cfoutput>
        Message Text: #messages[1].MsgText.XmlText#<br/>
        Message Level: #messages[1].MsgLevel.XmlText#
    </cfoutput>

    Inspiring
    October 7, 2010
    Note that you must also remove the xml declaration from the xml string before passing it to xmlparse().

    Ooh.  Why's that?

    --

    Adam

    Known Participant
    October 7, 2010

    oh, that was an error that I got when I tried to use xmlsearch going from the top to bottom of the xml file.