无效的xml&引用;发现以元素“开始的内容无效”;

无效的xml&引用;发现以元素“开始的内容无效”;,xml,xsd,xml-validation,Xml,Xsd,Xml Validation,我得到了这个XSD(简化): 这个XML示例(简化)是客户端将发送给我的格式: <?xml version="1.0" encoding="utf-16"?> <ns0:Employees xmlns:ns0="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Empl

我得到了这个XSD(简化):


这个XML示例(简化)是客户端将发送给我的格式:

<?xml version="1.0" encoding="utf-16"?>
<ns0:Employees xmlns:ns0="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Employee>

    </Employee>
</ns0:Employees>


xml不会根据XSD进行验证。我可以在XSD中更改什么来验证xml?

在XSD之后使用XSD。xml将根据此XSD进行验证

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:ns0="https://MDR.Employees.Schemas.MDREmployeePropertySchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" elementFormDefault="unqualified" targetNamespace="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:imports xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
        <b:namespace prefix="ns0" uri="https://MDR.Employees.Schemas.MDREmployeePropertySchema" location=".\mdremployeepropertyschema.xsd" />
      </b:imports>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Employees">
    <xs:annotation>
      <xs:appinfo>
        <b:properties>
          <b:property name="ns0:HeromaRefId" xpath="/*[local-name()='Employees' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']/*[local-name()='Employee' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']/*[local-name()='ID' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']" />
        </b:properties>
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Employee">
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

只需将elementFormDefault=“qualified”更改为elementFormDefault=“unqualified”。它会起作用的

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:ns0="https://MDR.Employees.Schemas.MDREmployeePropertySchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" elementFormDefault="unqualified" targetNamespace="http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:imports xmlns:b="http://schemas.microsoft.com/BizTalk/2003">
        <b:namespace prefix="ns0" uri="https://MDR.Employees.Schemas.MDREmployeePropertySchema" location=".\mdremployeepropertyschema.xsd" />
      </b:imports>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Employees">
    <xs:annotation>
      <xs:appinfo>
        <b:properties>
          <b:property name="ns0:HeromaRefId" xpath="/*[local-name()='Employees' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']/*[local-name()='Employee' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']/*[local-name()='ID' and namespace-uri()='http://schemas.customer.com/MdrEntitymodel/EmployeeExternalV1']" />
        </b:properties>
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Employee">
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>