使用WSO2中的脚本介体迭代XML数据

时间:2014-11-06 18:51:31

标签: javascript wso2esb

我的XML响应如下。

<getMyClsScheduleResponse xsi:schemaLocation="http://mais.he.umich.edu/schemas/getMyClsScheduleResponse.v1 http://csqa9ib.dsc.umich.edu/PSIGW/PeopleSoftServiceListeningConnector/getMyClsScheduleResponse.v1.xsd" xmlns="http://mais.he.umich.edu/schemas/getMyClsScheduleResponse.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <RegisteredClass>
    <ClassNumber>11509</ClassNumber>
    <SubjectCode>ENGLISH</SubjectCode>
    <CatalogNumber>225</CatalogNumber>
    <SectionNumber>001</SectionNumber>
    <SectionType>REC</SectionType>
    <SectionTypeDescr>Recitation</SectionTypeDescr>
    <SessionDescr>Regular</SessionDescr>
    <CourseDescr>Acad Argumentation</CourseDescr>
    <ClassTopic/>
    <CreditHours>4</CreditHours>
    <LMSURL>https://ctools.umich.edu/portal/site/d8457b9c-0e83-411a-abff-32ffa7899188</LMSURL>
    <Meeting>
      <MeetingNumber>1</MeetingNumber>
      <Days>TuTh</Days>
      <Times>10:00AM - 11:30AM</Times>
      <StartDate>09/02/2014</StartDate>
      <EndDate>12/10/2014</EndDate>
      <Location>2135 NQ</Location>
      <TopicDescr/>
    </Meeting>
    <Instructor>
      <InstructorName>Groce,Marian Renee</InstructorName>
      <LastName>Groce</LastName>
      <FirstName>Marian</FirstName>
      <Uniqname>MARIANGR</Uniqname>
      <InstructorRole>Secondary Instructor</InstructorRole>
    </Instructor>
    <Instructor>
      <InstructorName>Karageorgos,Konstantina Mary</InstructorName>
      <LastName>Karageorgos</LastName>
      <FirstName>Konstantina</FirstName>
      <Uniqname>KKARAGEO</Uniqname>
      <InstructorRole>Primary Instructor</InstructorRole>
    </Instructor>
  </RegisteredClass>
  <RegisteredClass>
    <ClassNumber>22595</ClassNumber>
    <SubjectCode>MKT</SubjectCode>
    <CatalogNumber>897</CatalogNumber>
    <SectionNumber>001</SectionNumber>
    <SectionType>SEM</SectionType>
    <SectionTypeDescr>Seminar</SectionTypeDescr>
    <SessionDescr>Scnd 7 Wk</SessionDescr>
    <CourseDescr>Quant Res Mkt</CourseDescr>
    <ClassTopic>Utopia</ClassTopic>
    <CreditHours>2</CreditHours>
    <LMSURL/>
    </RegisteredClass>
</getMyClsScheduleResponse>

`

我使用内联脚本调解器对此响应进行了一些更改。 见下文

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="BKKSDAcademics" transports="https,http" statistics="disable"
       trace="disable" startOnLoad="true">
       <target faultSequence="fault"
           endpoint="conf:/repository/esb/endpoints/MCommScholarId">
          <inSequence>
             <property name="Accept"
                   expression="$trp:Accept"
                   scope="default"
                   type="STRING"/>
      </inSequence>
      <outSequence>
         <log separator=",">
            <property name="Accept Name in Proxy EP is : "
                      expression="get-property('Accept')"/>
         </log>
         <script language="js">
         `var jslog = Packages.org.apache.commons.logging.LogFactory.getLog('debug.jsscript'); 
        var xmlResponse = mc.getPayloadXML();
        jslog.error('****IN BKKSDAcademics ***** '+ xmlResponse );
        jslog.error('****IN BKKSDAcademics RegisteredClass is ***** '+ xmlResponse..*::RegisteredClass );
        jslog.error('****IN BKKSDAcademics ClassNumberis ***** '+ xmlResponse..*::RegisteredClass.ClassNumber);    
        jslog.error('****IN BKKSDAcademics root is ***** '+ xmlResponse.root );
        jslog.error('****IN BKKSDAcademics elements length is ***** '+ xmlResponse.root.elements.length);`    

         mc.setPayloadJSON(xmlResponse);</script>
         <property name="messageType" value="application/json" scope="axis2"/>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="https://localhost:8080/TestService.wsdl"/>
   <description/>
</proxy>

日志不会打印整个XML ..有人可以建议一些想法来迭代javascript中的XML响应吗?

0 个答案:

没有答案