Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xml中执行枚举_Xml_Enums_Wsdl - Fatal编程技术网

如何在xml中执行枚举

如何在xml中执行枚举,xml,enums,wsdl,Xml,Enums,Wsdl,我有许多请求类型,它们实际上是枚举 但在我的代码中,这些请求类型是枚举: enum RequestType { RequestRegister, RequestUnregister, etc }; 下面是我当前对wsdl文件的尝试。但它使用字符串类型。在我的服务器中,我需要从xml中提取一个enum/int。查找字符串似乎是一个糟糕的设计 那么,如何形成wsdl文件,使请求类型为枚举 <?xml version="1.0" encoding="UTF-8"?> <

我有许多请求类型,它们实际上是枚举

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

enum RequestType {
  RequestRegister,
  RequestUnregister,
  etc
};
下面是我当前对wsdl文件的尝试。但它使用字符串类型。在我的服务器中,我需要从xml中提取一个enum/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>
在上述情况下,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>


我可能对限制基数是字符串有点困惑。restriction base=“string”是否表示枚举的名称是字符串?所有的名字都是字符串?在我的接收器代码中,我使用libxml。我想我关心的是libxml将如何提取操作系统版本?我需要看看libxml是如何处理枚举值的吗?
这样说:类型是一个字符串,但有这些额外的限制。是的,基本上是说名字是一个字符串。我不知道在libxml中需要做什么,我从来没有使用过它。在按类型而不是按元素属性指定零件元素时要小心。这使得父节点的名称空间未指定(与正确限定的节点子元素相反),使其名称空间定义易于解释,这可能导致互操作性问题。我认为将字符串表示为枚举更为自然。它使XML和解析代码更具可读性。而且任何性能差异都可能无关紧要——库和解析代码已经必须处理字符串,所以再多处理一点也不会有什么坏处。如果读取值的速度对您很重要,那么不要使用XML。
<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>