问题描述
我不知道我做错了什么? 我有 XSD 架构
<xs:complexType name="getTN_EO_DIC_OBJECTS">
<xs:sequence>
<xs:element name="TN_EO_DIC_OBJECTSRequest" type="tns:tnEODICOBJECTSRequest" form="qualified"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tnEODICOBJECTSRequest">
<xs:sequence>
<xs:element name="objectId" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Id объекта</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="classId" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Id класса (спраочника)</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="objectKod" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Код символьный</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
这一个 XSD 架构
我的选项 XSD TO XML
<ns0:getTN_EO_DIC_OBJECTS xmlns:ns0="http://service.siw.getcode.go/">
<ns0:TN_EO_DIC_OBJECTSRequest>
<ns0:tnEODICOBJECTSRequest>
<objectId>574</objectId>
<classId>4000</classId>
</ns0:tnEODICOBJECTSRequest>
</ns0:TN_EO_DIC_OBJECTSRequest>
</ns0:getTN_EO_DIC_OBJECTS>
它不起作用。 我应该怎么办? 我做错了什么?
解决方法
您确实需要发布完整的架构,但如果您的架构看起来像这样
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2021 (https://www.liquid-technologies.com)-->
<xs:schema xmlns:tns="http://service.siw.getcode.go/" elementFormDefault="qualified" targetNamespace="http://service.siw.getcode.go/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="getTN_EO_DIC_OBJECTS">
<xs:sequence>
<xs:element name="TN_EO_DIC_OBJECTSRequest" type="tns:tnEODICOBJECTSRequest" minOccurs="0" form="qualified" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="tnEODICOBJECTSRequest">
<xs:sequence>
<xs:element name="objectId" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Id объекта</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="classId" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Id класса (спраочника)</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="objectKod" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>Код символьный</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="Root" type="tns:getTN_EO_DIC_OBJECTS" />
</xs:schema>
那么您的示例 XML 将如下所示
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2021 (https://www.liquid-technologies.com) -->
<tns:Root xmlns:tns="http://service.siw.getcode.go/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://service.siw.getcode.go/ SO_67668466.xsd">
<tns:TN_EO_DIC_OBJECTSRequest>
<tns:objectId>-3997</tns:objectId>
<tns:classId>-12</tns:classId>
<tns:objectKod>3720</tns:objectKod>
</tns:TN_EO_DIC_OBJECTSRequest>
</tns:Root>
注意:在您的 XSD 中,getTN_EO_DIC_OBJECTS 被定义为 complexType,为了使用它,您必须定义一个 getTN_EO_DIC_OBJECTS 类型的元素(我创建了一个名为“root”的元素以创建有效的 XML 文档)。
添加架构后更新
您的架构无效。
<xs:schema xmlns:tns="http://service.go/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0"
targetNamespace="http://service.siw.pktbcki.rzd/">
<xs:element name="Reference12ASUResponse" type="tns:reference12ASUResponse"/>
看起来 xmlns:tns="http://service.go/"
应该是 xmlns:tns="http://service.siw.pktbcki.rzd/"
。
我认为另一个问题是架构没有指定 <xs:schema elementFormDefault="qualified"
(几乎所有架构都这样做),然后您的架构将一些元素定义为合格的,即 TN_EO_DIC_OBJECTSRequest
指定其命名空间应该是合格的.这使得确定哪些元素需要命名空间别名变得非常棘手。但在您的情况下,它看起来像是架构的有效 XML(注意 <tns:TN_EO_DIC_OBJECTSRequest>
上的 ns,但 <objectId>
上没有)
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2021 (https://www.liquid-technologies.com) -->
<tns:getTN_EO_DIC_OBJECTS xmlns:tns="http://service.siw.pktbcki.rzd/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://service.siw.pktbcki.rzd/ SO_67668466.xsd">
<tns:TN_EO_DIC_OBJECTSRequest>
<objectId>-4486</objectId>
<classId>2000</classId>
<objectKod>-4247</objectKod>
<objectKodstr>string</objectKodstr>
<objectVname>string</objectVname>
<objectName>string</objectName>
<objectSname>string</objectSname>
<refer>2060</refer>
<s1>string</s1>
<i1>-475</i1>
<komm>string</komm>
<corTip>string</corTip>
<dateNd>2001-01-15T04:53:04.70</dateNd>
<dateKd>2011-10-07T16:16:02.20</dateKd>
<corTime>1993-10-18T10:43:28.61</corTime>
<operId>-3192</operId>
<dorNsi>string</dorNsi>
</tns:TN_EO_DIC_OBJECTSRequest>
</tns:getTN_EO_DIC_OBJECTS>