当前位置 : 主页 > 网页制作 > xml >

如何在xml中执行枚举

来源:互联网 收集:自由互联 发布时间:2021-06-13
我有许多请求类型 – 它们确实是枚举. 但在我的代码中,这些请求类型是一个枚举: enum RequestType { RequestRegister, RequestUnregister, etc}; 我目前对wsdl文件的尝试如下.但它使用字符串类型.在我
我有许多请求类型 – 它们确实是枚举.

但在我的代码中,这些请求类型是一个枚举:

enum RequestType {
  RequestRegister,
  RequestUnregister,
  etc
};

我目前对wsdl文件的尝试如下.但它使用字符串类型.在我的服务器中,我需要从xml中提取枚举/ int.对字符串进行查找似乎是糟糕的设计.

那么我如何形成我的wsdl文件,以便请求类型是枚举?

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="CubaCTI"
targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.iteloffice.com/wsdl/cubacti.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<message name="MonitorStartRequest">
 <part name="user_name" type="xsd:string" />
 <part name="password" type="xsd:string" />
 <part name="dn" type="xsd:string"/>
</message>
<message name="MonitorStartResponse">
 <part name="errorcode" type="xsd:short"/>
 <part name="errormessage" type="xsd:string"/>
</message>

<message name="MonitorStopRequest">
 <part name="user_name" type="xsd:string" />
 <part name="password" type="xsd:string" />
 <part name="dn" type="xsd:string"/>
</message>
<message name="MonitorStopResponse">
 <part name="errorcode" type="xsd:short"/>
 <part name="errormessage" type="xsd:string"/>
</message>

<message name="MakeCallRequest">
 <part name="user_name" type="xsd:string" />
 <part name="password" type="xsd:string" />
 <part name="dn" type="xsd:string"/>
 <part name="destination" type="xsd:string"/>
 <part name="userdata" type="xsd:string"/>
</message>
<message name="MakeCallResponse">
 <part name="errorcode" type="xsd:short"/>
 <part name="errormessage" type="xsd:string"/>
</message>

<message name="ClearConnectionRequest">
 <part name="user_name" type="xsd:string" />
 <part name="password" type="xsd:string" />
 <part name="dn" type="xsd:string"/>
 <part name="destinationconnectionid" type="xsd:string"/>
</message>
<message name="ClearConnectionResponse">
 <part name="errorcode" type="xsd:short"/>
 <part name="errormessage" type="xsd:string"/>
</message>

<portType name="CubaCTIRequests">
  <operation name="MonitorStart">
     <input message="tns:MonitorStartRequest"/>
     <output message="tns:MonitorStartResponse"/>
  </operation>
  <operation name="MonitorStop">
     <input message="tns:MonitorStopRequest"/>
     <output message="tns:MonitorStopResponse"/>
  </operation>
  <operation name="MakeCall">
     <input message="tns:MakeCallRequest"/>
     <output message="tns:MakeCallResponse"/>
  </operation>
  <operation name="ClearConnection">
     <input message="tns:ClearConnectionRequest"/>
     <output message="tns:ClearConnectionResponse"/>
  </operation>

</portType>

<binding type="tns:CubaCTIRequests" name="cubactibinding">
 <soap:binding style="document"
       transport="http://schemas.xmlsoap.org/soap/http" />

 <operation name="MonitorStart">
   <soap:operation soapAction="MonitorStart"/>
   <input>
      <soap:body use="literal"/>
   </input>
   <output>
      <soap:body use="literal"/>
   </output>
 </operation>

 <operation name="MonitorStop">
   <soap:operation soapAction="MonitorStop"/>
   <input>
      <soap:body
           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
           namespace="http://www.iteloffice.com/cubctirequests"
           use="encoded"/>
   </input>
   <output>
      <soap:body
           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
           namespace="http://www.iteloffice.com/cubctirequests"
           use="literal"/>
   </output>
 </operation>

 <operation name="MakeCall">
   <soap:operation soapAction="MakeCall"/>
   <input>
      <soap:body use="literal"/>
   </input>
   <output>
      <soap:body use="literal"/>
   </output>
 </operation>

 <operation name="ClearConnection">
   <soap:operation soapAction="ClearConnection"/>
   <input>
      <soap:body use="literal"/>
   </input>
   <output>
      <soap:body use="literal"/>
   </output>
 </operation>


</binding>


<service name="CubaCTI_Service">
  <documentation>WSDL File for Cuba CTI services</documentation>
   <port binding="tns:cubactibinding" name="CubaCTIRequestsBinding">
     <soap:address 
        location="http://angusnotebook:8080"/>
   </port>
 </service>
</definitions>

附加说明.

我被“强制”使用xml,因为客户端只能发送xml消息(无法控制).但是我组成了客户端使用的xml.我控制/写入的服务器是用C语言编写的,我使用libxml来提取xml文件的“部分”.理想情况下,该项目将是int或enum.因为我想这样做:

//从xml中提取项目 – 进入枚举或int
   RequestType rqtype = getRequestType();

switch(rqtype) {
 case RequestMakeCall:
  //do whatever

在上面的例子中,RequestType是一个枚举.提取字符串值然后必须查找相关的枚举值是没有效率的.

我看到枚举的所有例子似乎都使用字符串,这看起来很奇怪.

您可以创建自己的类型:

<definitions targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl"
             xmlns:tns="Mediaresearch.SimNet.Communication" 
             xmlns:s="http://www.w3.org/2001/XMLSchema"
             xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <s:schema elementFormDefault="qualified"
              targetNamespace="http://www.iteloffice.com/wsdl/cubacti.wsdl">
      <s:simpleType name="OperatingSystemVersion">
        <s:restriction base="s:string">
          <s:enumeration value="None" />
          <s:enumeration value="WinXp" />
          <s:enumeration value="WinVista" />
          <s:enumeration value="Win7" />
        </s:restriction>
      </s:simpleType>
    </s:schema>
  </types>
  <message name="OperatingSystemVersion">
    <part name="user_name" type="tns:OperatingSystemVersion" />
  </message>
</definitions>
网友评论