【问题标题】:Invalid xml. "Invalid Content Was Found Starting With Element"无效的 xml。 “发现以元素开头的无效内容”
【发布时间】:2014-01-22 14:33:47
【问题描述】:

我已收到此 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="qualified" 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>

这个 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?

【问题讨论】:

    标签: xml xsd xml-validation


    【解决方案1】:

    在 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"。它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 2016-01-22
      • 2013-05-10
      • 1970-01-01
      相关资源
      最近更新 更多