【问题标题】:XSD scheme syntax and gSoapXSD 方案语法和 gSoap
【发布时间】:2017-02-06 09:08:01
【问题描述】:

我有一个问题,这个 XSD 语法有效吗?因为当我使用 gSOAP 时,它会警告我,因为它会创建结构(C/C++ 代码),该结构由两个具有相同名称(名称 C)的其他结构组成,然后当我尝试在 c/c++ 编译器中编译该代码时它产生错误(因为在一个结构中具有相同名称的结构)。这里有没有可能在不接触 XSD 文件的情况下解决这个问题?

<complexType name="A">
<choice>
<sequence>
<element name="B" type="base64Binary"/>
<element name="C" type="base64Binary" minOccurs="0"/>
<any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<sequence>
<element name="C" type="base64Binary"/>
<any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</choice>
</complexType>

在 gSOAP 中我使用:wsdl2h.exe -oSoap.h -s -y -c a.wsdl b.wsdl ...

soapcpp2.exe -C -L -n -x -w -c -d.\source Soap.h

【问题讨论】:

  • @KeineLust,gSoap生成C/C++代码,出现一个struct中的两个struct同名的问题。
  • ok ;) 你能显示这些警告吗?
  • error: redefinition of 'struct a::c'error: previous definition of 'struct a::c'
  • @МартинБее 准确地说,这些不仅仅是警告,它们是错误。
  • @user2079303,我同意对不起,我从 gSoap 编译器收到警告,它从带有警告的 xml 创建 c/c++ 代码,然后此代码在 c/c++ 编译器中编译后产生错误。

标签: c++ c xml xsd gsoap


【解决方案1】:

是的,它是有效的 XSD 语法;它看起来像是您的代码生成器无法处理的情况。

【讨论】:

  • 对不起,这个答案不正确。是的,它是有效的 XSD。但是代码生成器并没有对此出错。这只是一个警告。我使用过这样的代码,我可以证明代码生成器可以很好地处理这个 XSD。
【解决方案2】:

soapcpp2 工具只会报错,但生成的代码是按设计工作的。我对此进行了研究并对其进行了测试。

这是我由 soapcpp2 生成的:

class ns__A
{ public:
//  BEGIN CHOICE <xs:choice>
/// @note <xs:choice> with embedded <xs:sequence> or <xs:group> prevents the use of a union for <xs:choice>. Instead of being members of a union, the following members are declared optional. Only one member should be non-NULL by choice.
//  BEGIN SEQUENCE <xs:sequence>
/// Element "B" of XSD type xs:base64Binary.
    xsd__base64Binary*                   B                              nullptr;    ///< Required nillable (xsi:nil when NULL) element.
/// Element "C" of XSD type xs:base64Binary.
    xsd__base64Binary*                   C                             ;    ///< Required element.
/// Size of the array of XML or DOM nodes is 0..unbounded.
    std::vector<_XML                   > __any                         0;   ///< Catch any element content in XML string.
//  END OF SEQUENCE
//  BEGIN SEQUENCE <xs:sequence>
/// Element "C" of XSD type xs:base64Binary.
    xsd__base64Binary*                   C                              nullptr;    ///< Required nillable (xsi:nil when NULL) element.
/// Size of the array of XML or DOM nodes is 0..unbounded.
    std::vector<_XML                   > __any                         0;   ///< Catch any element content in XML string.
//  END OF SEQUENCE
//  END OF CHOICE
/// A handle to the soap struct context that manages this instance when instantiated by a context or NULL otherwise (automatically set).
    struct soap                         *soap                          ;
};

soapcpp2 报告“问题”的原因是流式序列化程序无法区分C 的选择。所以两者都是编码的。第二个C 被重命名为C_ 并且从不用于反序列化数据。

简单的解释:你很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2017-08-10
    • 2012-11-16
    • 2023-03-05
    • 2013-07-09
    相关资源
    最近更新 更多