3 Replies Latest reply: Apr 2, 2013 4:19 AM by KalpanaJgl RSS

    XQuery transformation: 'bad value for type element' error

    KalpanaJgl
      Hi,

      I am transforming the data from A.xsd to B.xsd which are shown below:

      A.xsd:

      <?xml version="1.0" encoding="UTF-8" ?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns="http://www.example.org"
      targetNamespace="http://www.example.org"
      elementFormDefault="qualified">
      <xsd:element name="EAIMESSAGE">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="EAIHEADER">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="CONVERSATIONID" type="xsd:string"/>
      <xsd:element name="TIMESTAMP" type="xsd:string"/>
      <xsd:element name="APPSPECIFICINFO">
      <xsd:complexType>
      <xsd:attribute name="NAME" type="xsd:string"/>
      <xsd:attribute name="VALUE" type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EAIPAYLOAD">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="MESSAGE">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="RECORD" maxOccurs="unbounded">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="RECORDHEADER" minOccurs="0">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="PRIMARY_KEY_FIELD"
      type="xsd:string"/>
      <xsd:element name="PRIMARY_KEY"
      type="xsd:string"/>
      <xsd:element name="DELIMITER"
      type="xsd:string"/>
      <xsd:element name="OPCODE" type="xsd:string"/>
      <xsd:element name="APP_SEQUENCE_NO"
      type="xsd:string"/>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RECORDDATA" minOccurs="0">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="Rover_KEY">
      <xsd:complexType>
      <xsd:simpleContent>
      <xsd:extension base="xsd:string">
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:extension>
      </xsd:simpleContent>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RPT_FLD1">
      <xsd:complexType>
      <xsd:simpleContent>
      <xsd:extension base="xsd:string">
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:extension>
      </xsd:simpleContent>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="AP_COMMUNICATION_TYPE">
      <xsd:complexType>
      <xsd:simpleContent>
      <xsd:extension base="xsd:string">
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      <xsd:attribute name="BLOBORCLOBURL"
      type="xsd:string"/>
      <xsd:attribute name="COMPRESSION"
      type="xsd:string"/>
      <xsd:attribute name="ENCODED"
      type="xsd:string"/>
      </xsd:extension>
      </xsd:simpleContent>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EMAIL_TO">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      <xsd:attribute name="BLOBORCLOBURL"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EMAIL_BCC">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      <xsd:attribute name="BLOBORCLOBURL"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EMAIL_CC">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EMAIL_FROM">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="EMAIL_SUBJECT">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="ERROR_MESSAGE">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="MESSAGE_ID">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RPT_FLD2">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="PHONE_NUMBER">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:integer"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RPT_FLD4">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="PRINTER_NAME">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="AP_REQUESTCREATEDATE">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:dateTime"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="REQUEST_STATUS">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="REQUEST_ID">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RESPONSEDATE">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="TEMPLATENAME">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RPT_FLD5">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="RPT_FLD3">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="GROUP_NAME">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="SUBGROUP_NAME">
      <xsd:complexType>
      <xsd:attribute name="DATATYPE"
      type="xsd:string"/>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:schema>


      B.xsd:

      <?xml version= '1.0' encoding= 'UTF-8' ?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns="http://gcrm.apple.com/notification"
           targetNamespace="http://gcrm.apple.com/notification"
           elementFormDefault="qualified">
           <xsd:element name="Event">
                <xsd:annotation>
                     <xsd:documentation>Event schema</xsd:documentation>
                </xsd:annotation>
                <xsd:complexType>
                     <xsd:sequence>
                          <xsd:element name="EventHeader">
                               <xsd:complexType>
                                    <xsd:sequence>
                                         <xsd:element name="eventId" type="xsd:string" />
                                         <xsd:element name="eventName" type="xsd:string" />
                                         <xsd:element name="eventType" type="xsd:string" />
                                         <xsd:element name="applicationId" type="xsd:int" />
                                         <xsd:element name="eventSource" type="xsd:string" />
                                         <xsd:element name="creationDateTime" type="xsd:dateTime" />
                                         <xsd:element name="taskId" type="xsd:string" minOccurs="0" maxOccurs="1"/>
                                         <xsd:element name="componentId" type="xsd:string" minOccurs="0" maxOccurs="1" />
                                         <xsd:element name="headerExt" minOccurs="0" maxOccurs="1">
                                              <xsd:complexType>
                                                   <xsd:sequence>
                                                        <xsd:element name="nameValuePair" maxOccurs="unbounded">
                                                             <xsd:complexType>
                                                                  <xsd:sequence>
                                                                       <xsd:element name="name" />
                                                                       <xsd:element name="value" />
                                                                  </xsd:sequence>
                                                             </xsd:complexType>
                                                        </xsd:element>
                                                   </xsd:sequence>
                                              </xsd:complexType>
                                         </xsd:element>
                                    </xsd:sequence>
                               </xsd:complexType>
                          </xsd:element>
                          <xsd:element name="ApplicationDataArea">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="roverTransaction">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="roverKey" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="reportField1" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="communicationType" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="emailTo" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="emailBCC" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="emailCC" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="emailFrom" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="emailSubject" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="errorMessage" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="messageID" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="reportField2" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="phoneNumber" nillable= "true" minOccurs="0" type="xsd:integer"/>
      <xsd:element name="reportField4" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="printerName" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="requestCreateDate" nillable= "true" minOccurs="0" type="xsd:dateTime"/>
      <xsd:element name="requestStatus" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="requestID" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="responseDate" nillable= "true" minOccurs="0" type="xsd:dateTime"/>
      <xsd:element name="templateName" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="reportField5" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="reportField3" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="groupName" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="subGroupName" nillable= "true" minOccurs="0" type="xsd:string"/>
      <xsd:element name="optionalAttribute" minOccurs="0">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="keyValuePair" maxOccurs="unbounded">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="key" type="xsd:string"/>
      <xsd:element name="value" type="xsd:string"/>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:sequence>
      </xsd:complexType>
                          </xsd:element>
                          <xsd:element ref="EventAction" minOccurs="0" maxOccurs="1" />
                          <xsd:element name="AppResponse" minOccurs="0">
                               <xsd:complexType>
                                    <xsd:sequence>
                                         <xsd:element name="Status" type="StatusType" />
                                         <xsd:element name="Message" type="xsd:string" />
                                    </xsd:sequence>
                               </xsd:complexType>
                          </xsd:element>

                          <xsd:element name="AppTaskActionInfo" minOccurs="0">
                               <xsd:complexType>
                                    <xsd:sequence>
                                         <xsd:element name="AppTaskURL" type="xsd:string" />
                                         <xsd:element name="AppTaskXSL" type="xsd:string" />
                                         <xsd:element name="ActionContext" maxOccurs="unbounded">
                                              <xsd:complexType>
                                                   <xsd:sequence>
                                                        <xsd:element name="Role" type="xsd:string" />
                                                        <xsd:element name="DSid" type="xsd:string" />
                                                        <xsd:element name="Context" type="xsd:string"
                                                             maxOccurs="unbounded" />
                                                   </xsd:sequence>
                                              </xsd:complexType>
                                         </xsd:element>
                                    </xsd:sequence>
                               </xsd:complexType>
                          </xsd:element>
                     </xsd:sequence>
                </xsd:complexType>
           </xsd:element>
           
           <xsd:element name="EventAction">
                <xsd:complexType>
                     <xsd:sequence>
                          <xsd:element name="subscriptionActions" maxOccurs="unbounded">
                               <xsd:complexType>
                                    <xsd:sequence>
                                         <xsd:element name="role" type="xsd:string" />
                                         <xsd:element name="template" type="xsd:string"
                                              maxOccurs="unbounded" />
                                         <xsd:element name="emailId" type="xsd:string"
                                              maxOccurs="unbounded" />
                                         <xsd:element name="smsNumber" type="xsd:string"
                                              maxOccurs="unbounded" />
                                         <xsd:element name="userId" type="xsd:string" />
                                         <xsd:element name="toBeNotifiedByMail" type="xsd:boolean" />
                                         <xsd:element name="toBeNotifiedBySMS" type="xsd:boolean" />
                                         <xsd:element name="applicationTask" type="xsd:string" />
                                         <xsd:element name="context" type="xsd:string"
                                              maxOccurs="unbounded" />
                                         <xsd:element name="checkdata" type="xsd:string" />
                                         <xsd:element name="actionMetaData" maxOccurs="unbounded">
                                              <xsd:complexType>
                                                   <xsd:sequence>
                                                        <xsd:element name="name" />
                                                        <xsd:element name="value" />
                                                   </xsd:sequence>
                                              </xsd:complexType>
                                         </xsd:element>
                                    </xsd:sequence>
                               </xsd:complexType>
                          </xsd:element>
                     </xsd:sequence>
                </xsd:complexType>
           </xsd:element>
           <xsd:simpleType name="StatusType">
                <xsd:restriction base="xsd:string">
                     <xsd:enumeration value="ERROR" />
                     <xsd:enumeration value="WARNING" />
                     <xsd:enumeration value="SUCCESS" />
                </xsd:restriction>
           </xsd:simpleType>
      </xsd:schema>

      Below is the A_to_B.xq::

      (:: pragma bea:global-element-parameter parameter="$eAIMESSAGE1" element="ns0:EAIMESSAGE" location="../xsd/EAISchema.xsd" ::)
      (:: pragma bea:global-element-return element="ns1:Event" location="../xsd/AURAEvent.xsd" ::)

      declare namespace ns1 = "http://gcrm.apple.com/notification";
      declare namespace ns0 = "http://www.example.org";
      declare namespace xf = "http://tempuri.org/AURA/CONSUMERS/AURA_ROVER_PROJECT/xq/one/";

      declare function xf:one($eAIMESSAGE1 as element(ns0:EAIMESSAGE))
      as element(ns1:Event) {
      <ns1:Event>
      <ns1:ApplicationDataArea>
      <ns1:roverTransaction>
      <ns1:roverKey>{ data($eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:Rover_KEY) }</ns1:roverKey>
      <ns1:reportField1>{ data($eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RPT_FLD1) }</ns1:reportField1>
      <ns1:communicationType>{ data($eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:AP_COMMUNICATION_TYPE) }</ns1:communicationType>
      {
      let $EMAIL_TO := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:EMAIL_TO
      return
      <ns1:emailTo/>
      }
      {
      let $EMAIL_BCC := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:EMAIL_BCC
      return
      <ns1:emailBCC/>
      }
      {
      let $EMAIL_CC := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:EMAIL_CC
      return
      <ns1:emailCC/>
      }
      {
      let $EMAIL_FROM := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:EMAIL_FROM
      return
      <ns1:emailFrom/>
      }
      {
      let $EMAIL_SUBJECT := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:EMAIL_SUBJECT
      return
      <ns1:emailSubject/>
      }
      {
      let $ERROR_MESSAGE := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:ERROR_MESSAGE
      return
      <ns1:errorMessage/>
      }
      {
      let $MESSAGE_ID := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:MESSAGE_ID
      return
      <ns1:messageID/>
      }
      {
      let $RPT_FLD2 := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RPT_FLD2
      return
      <ns1:reportField2/>
      }
      {
      let $PHONE_NUMBER := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:PHONE_NUMBER
      return
      <ns1:phoneNumber/>
      }
      {
      let $RPT_FLD4 := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RPT_FLD4
      return
      <ns1:reportField4/>
      }
      {
      let $PRINTER_NAME := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:PRINTER_NAME
      return
      <ns1:printerName/>
      }
      {
      let $AP_REQUESTCREATEDATE := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:AP_REQUESTCREATEDATE
      return
      <ns1:requestCreateDate/>
      }
      {
      let $REQUEST_STATUS := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:REQUEST_STATUS
      return
      <ns1:requestStatus/>
      }
      {
      let $REQUEST_ID := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:REQUEST_ID
      return
      <ns1:requestID/>
      }
      {
      let $RESPONSEDATE := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RESPONSEDATE
      return
      <ns1:responseDate/>
      }
      {
      let $TEMPLATENAME := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:TEMPLATENAME
      return
      <ns1:templateName/>
      }
      {
      let $RPT_FLD5 := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RPT_FLD5
      return
      <ns1:reportField5/>
      }
      {
      let $RPT_FLD3 := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:RPT_FLD3
      return
      <ns1:reportField3/>
      }
      {
      let $GROUP_NAME := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:GROUP_NAME
      return
      <ns1:groupName/>
      }
      {
      let $SUBGROUP_NAME := $eAIMESSAGE1/ns0:EAIPAYLOAD/ns0:MESSAGE/ns0:RECORD[1]/ns0:RECORDDATA/ns0:SUBGROUP_NAME
      return
      <ns1:subGroupName/>
      }
      </ns1:roverTransaction>
      </ns1:ApplicationDataArea>
      </ns1:Event>
      };

      declare variable $eAIMESSAGE1 as element(ns0:EAIMESSAGE) external;

      xf:one($eAIMESSAGE1)


      When i test this XQuery i am getting the below error:

      OSB Replace action failed updating variable "body": Error parsing XML: {err}XP0006: "element {http://schemas.xmlsoap.org/soap/envelope/}Body { {http://www.w3.org/2004/07/xpath-datatypes}untypedAny }": bad value for type element {http://www.example.org}EAIMESSAGE { {http://www.w3.org/2001/XMLSchema}anyType }

      Kindly help me in resolving the same.

      Thanks in advance.