Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml Minoccur不在XSD中工作?_Xml_Xsd - Fatal编程技术网

Xml Minoccur不在XSD中工作?

Xml Minoccur不在XSD中工作?,xml,xsd,Xml,Xsd,在我的场景中,每次xsd都是动态出现的,我将使用固定的xsd对XML进行验证, 当xml中缺少一个关键字时,其返回的所有必填和非必填关键字都将丢失 XML: <?xml version="1.0" encoding="utf-8"?> <Invoice> <Invoice_Header> <lastname>str1234</lastname> <fathername>str1234</father

在我的场景中,每次xsd都是动态出现的,我将使用固定的xsd对XML进行验证,
当xml中缺少一个关键字时,其返回的所有必填和非必填关键字都将丢失

XML

<?xml version="1.0" encoding="utf-8"?>
<Invoice>
  <Invoice_Header>
    <lastname>str1234</lastname>
    <fathername>str1234</fathername>
    <mothername>str1234</mothername>
    <gender>str1234</gender>
    <age>123</age>
    <college>str1234</college>
    <city>str1234</city>
  </Invoice_Header>
</Invoice>

str1234
str1234
str1234
str1234
123
str1234
str1234
XSD:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"           xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Invoice">
<xs:complexType>
  <xs:sequence>
    <xs:element name="Invoice_Header">
      <xs:complexType>
        <xs:all>
          <xs:element type="xs:string" name="fisrtname" />
          <xs:element type="xs:string" name="lastname" minOccurs="0"/>
          <xs:element type="xs:string" name="fathername"/>
          <xs:element type="xs:string" name="mothername" minOccurs="0"/>
          <xs:element type="xs:string" name="gender"/>
          <xs:element type="xs:int" name="age"/>
          <xs:element type="xs:string" name="college" minOccurs="0"/>
          <xs:element type="xs:string" name="city" minOccurs="0"/>
        </xs:all>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

在上面的XML中缺少名字,但我得到的错误如下 所有{firstnaem,lastname,fathername,mothername,gender,age,college,city}中的一个应该是

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"           xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Invoice">
<xs:complexType>
  <xs:sequence>
    <xs:element name="Invoice_Header">
      <xs:complexType>
        <xs:all>
          <xs:element type="xs:string" name="fisrtname" />
          <xs:element type="xs:string" name="lastname" minOccurs="0"/>
          <xs:element type="xs:string" name="fathername"/>
          <xs:element type="xs:string" name="mothername" minOccurs="0"/>
          <xs:element type="xs:string" name="gender"/>
          <xs:element type="xs:int" name="age"/>
          <xs:element type="xs:string" name="college" minOccurs="0"/>
          <xs:element type="xs:string" name="city" minOccurs="0"/>
        </xs:all>
      </xs:complexType>
    </xs:element>
  </xs:sequence>
</xs:complexType>

有谁能帮我了解一下如何只获取必填关键字?仅缺少信息

模式处理器不太可能允许自定义您要求的错误消息。不同的处理器将产生不同的诊断。值得一提的是,这是Saxon的错误消息:

Validation error on line 3 column 21 of test.xml:
  In content of element <Invoice_Header>: element <fisrtname> is not present
  See http://www.w3.org/TR/xmlschema-1/#cvc-model-group clause 3
test.xml第3行第21列的验证错误: 元素内容中:元素不存在 看见http://www.w3.org/TR/xmlschema-1/#cvc-示范小组第3条
是的,我正在使用saxparserexception捕获错误消息