xml xsd验证调试
第一次使用xml xsd。xml xsd验证调试,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,第一次使用xml xsd。 我有如下xsd和xml数据。当我尝试验证时,会出现错误。 下面是代码和错误 请帮我找出哪里出了问题 XSD: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://www.m5net.com/mantle/configuration/connectors" targetNamespa
我有如下xsd和xml数据。当我尝试验证时,会出现错误。
下面是代码和错误 请帮我找出哪里出了问题 XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://www.m5net.com/mantle/configuration/connectors" targetNamespace="http://www.m5net.com/mantle/configuration/connectors" elementFormDefault="qualified">
<xsd:element name="Bullhorn" type="t:Bullhorn" nillable="true" />
<xsd:element name="Configuration" type="t:Configuration" nillable="true" />
<xsd:element name="Lync" type="t:Lync" nillable="true" />
<xsd:element name="SalesForce" type="t:SalesForce" nillable="true" />
<xsd:element name="ShoreTelCosmoMobility" type="t:ShoreTelCosmoMobility" nillable="true" />
<xsd:element name="ShoreTelCosmoScribe" type="t:ShoreTelCosmoScribe" nillable="true" />
<xsd:element name="ShoreTelFax" type="t:ShoreTelFax" nillable="true" />
<xsd:element name="ShoreTelMobility" type="t:ShoreTelMobility" nillable="true" />
<xsd:element name="ShoreTelScribe" type="t:ShoreTelScribe" nillable="true" />
<xsd:element name="ShoretelCosmoConference" type="t:ShoretelCosmoConference" nillable="true" />
<xsd:element name="ShoretelCosmoMobility" type="t:ShoretelCosmoMobility" nillable="true" />
<xsd:complexType name="Bullhorn">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" />
<xsd:element name="CorporationID" type="xsd:int" minOccurs="0" />
<xsd:element name="Password" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="PrivateLabelID" type="xsd:int" minOccurs="0" />
<xsd:element name="UserName" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Configuration">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Lync">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="TrustedAppComputerFQDN" type="xsd:string" />
<xsd:element name="TrustedAppPort" type="xsd:int" />
<xsd:element name="TrustedAppComputerGRUU" type="xsd:string" />
<xsd:element name="CertificateFriendlyName" type="xsd:string" />
<xsd:element name="TrustedAppEndpointOwnerURI" type="xsd:string" />
<xsd:element name="RegistrarFQDN" type="xsd:string" />
<xsd:element name="RegistrarPort" type="xsd:int" />
<xsd:element name="AccountId" type="xsd:int" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SalesForce">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="IsSandbox" type="xsd:boolean" minOccurs="0" />
<xsd:element name="Password" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="Token" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="UserName" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoreTelCosmoMobility">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" nillable="true" />
<xsd:element name="GroupId" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoreTelCosmoScribe">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" nillable="true" />
<xsd:element name="GroupId" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoreTelFax">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" />
<xsd:element name="ConfirmReceipt" type="xsd:int" minOccurs="0" />
<xsd:element name="ConfirmSent" type="xsd:int" minOccurs="0" />
<xsd:element name="IncludeCover" type="xsd:int" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoreTelMobility">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" />
<xsd:element name="GroupID" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoreTelScribe">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" />
<xsd:element name="PlanId" type="xsd:int" minOccurs="0" />
<xsd:element name="SendImmediate" type="xsd:int" minOccurs="0" />
<xsd:element name="SubplanId" type="xsd:int" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoretelCosmoConference">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" nillable="true" />
<xsd:element name="StartConference" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="EndConference" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="WebLoginMode" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="Password" type="xsd:string" minOccurs="0" nillable="true" />
<xsd:element name="OutdialPrompt" type="xsd:boolean" minOccurs="0" />
<xsd:element name="NotifyChanges" type="xsd:boolean" minOccurs="0" />
<xsd:element name="NotificationEmail" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ShoretelCosmoMobility">
<xsd:complexContent>
<xsd:extension base="t:Configuration">
<xsd:sequence>
<xsd:element name="AccountId" type="xsd:int" minOccurs="0" nillable="true" />
<xsd:element name="GroupId" type="xsd:string" minOccurs="0" nillable="true" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
我认为问题在于元素的顺序,因为NotificationEmail
是模式中的最后一个元素。尝试对数据重新排序,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<ShoretelCosmoConference xmlns="http://www.m5net.com/mantle/configuration/connectors" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AccountId>13284</AccountId>
<StartConference>Host Joins</StartConference>
<EndConference>Moderator leaves</EndConference>
<WebLoginMode>Name Only</WebLoginMode>
<Password />
<OutdialPrompt>true</OutdialPrompt>
<NotifyChanges>false</NotifyChanges>
<NotificationEmail />
</ShoretelCosmoConference>
它说这个错误发生了:
错误-第6行,第19行:org.xml.sax.SAXParseException;行号:6;栏目号:19;cvc复杂类型.2.4.d:发现以元素“NotifyChanges”开头的无效内容。此时不需要任何子元素
我重写了xsd模式,发现顺序确实很重要:
<?xml version="1.0" encoding="UTF-8"?>
<ShoretelCosmoConference xmlns="http://www.m5net.com/mantle/configuration/connectors" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AccountId>13284</AccountId>
<StartConference>Host Joins</StartConference>
<EndConference>Moderator leaves</EndConference>
<WebLoginMode>Name Only</WebLoginMode>
<Password />
<OutdialPrompt>true</OutdialPrompt>
<NotifyChanges>false</NotifyChanges>
<NotificationEmail />
</ShoretelCosmoConference>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.m5net.com/mantle/configuration/connectors" elementFormDefault="qualified" targetNamespace="http://www.m5net.com/mantle/configuration/connectors">
<xs:complexType name="ShoretelCosmoConference">
<xs:sequence>
<xs:element minOccurs="0" name="AccountId" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="StartConference" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="EndConference" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="WebLoginMode" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="OutdialPrompt" type="xs:boolean" />
<xs:element minOccurs="0" name="NotifyChanges" type="xs:boolean" />
<xs:element minOccurs="0" name="NotificationEmail" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="ShoretelCosmoConference" nillable="true" type="tns:ShoretelCosmoConference" />
</xs:schema>
13284
主机连接
调节叶
仅此而已
真的
假的
结果:
XML格式良好且有效
我在一些博客上读到顺序无关紧要。不过,让我试试看。请注意,错误在NotifyChanges中,而不是在NotifyChanges中NotificationEmail@Raghav嗯,你说得对,顺序不重要。这可能是因为您的代码是
,而不是
@Raghav请参阅Update@Raghav不要相信你在博客上读到的一切。使用
时,xml中元素的顺序必须是顺序(顺序正确)。能否为tns:Configuration
提供XSD模式?我想这是最重要的problem@Raghav请在问题中添加xsd
和xml
代码,这样问题陈述就完整了。
<?xml version="1.0" encoding="UTF-8"?>
<ShoretelCosmoConference xmlns="http://www.m5net.com/mantle/configuration/connectors" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AccountId>13284</AccountId>
<StartConference>Host Joins</StartConference>
<EndConference>Moderator leaves</EndConference>
<WebLoginMode>Name Only</WebLoginMode>
<Password />
<OutdialPrompt>true</OutdialPrompt>
<NotifyChanges>false</NotifyChanges>
<NotificationEmail />
</ShoretelCosmoConference>
<?xml version="1.0" encoding="UTF-8"?>
<ShoretelCosmoConference xmlns="http://www.m5net.com/mantle/configuration/connectors" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AccountId>13284</AccountId>
<StartConference>Host Joins</StartConference>
<EndConference>Moderator leaves</EndConference>
<WebLoginMode>Name Only</WebLoginMode>
<Password />
<OutdialPrompt>true</OutdialPrompt>
<NotifyChanges>false</NotifyChanges>
<NotificationEmail />
</ShoretelCosmoConference>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.m5net.com/mantle/configuration/connectors" elementFormDefault="qualified" targetNamespace="http://www.m5net.com/mantle/configuration/connectors">
<xs:complexType name="ShoretelCosmoConference">
<xs:sequence>
<xs:element minOccurs="0" name="AccountId" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="StartConference" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="EndConference" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="WebLoginMode" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="OutdialPrompt" type="xs:boolean" />
<xs:element minOccurs="0" name="NotifyChanges" type="xs:boolean" />
<xs:element minOccurs="0" name="NotificationEmail" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="ShoretelCosmoConference" nillable="true" type="tns:ShoretelCosmoConference" />
</xs:schema>