Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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生成架构验证定义_Xml_Validation_Schema - Fatal编程技术网

为自定义XML生成架构验证定义

为自定义XML生成架构验证定义,xml,validation,schema,Xml,Validation,Schema,我在写下XML文件的模式时遇到了一些问题,这非常简单 按照我的建议,我尝试放置其他代码(我删除了该代码,因为如果我把所有事情都搞砸了,我无法取消绑定…): 我无法找出我的模式的问题在哪里: <?xml version="1.0" standalone="yes"?> <ChangeHistory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xs:schema id="ChangeHi

我在写下XML文件的模式时遇到了一些问题,这非常简单

按照我的建议,我尝试放置其他代码(我删除了该代码,因为如果我把所有事情都搞砸了,我无法取消绑定…):

我无法找出我的模式的问题在哪里:

<?xml version="1.0"
      standalone="yes"?>
<ChangeHistory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xs:schema id="ChangeHistory"
             xmlns=""
             xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="ChangeHistory"
                msdata:IsDataSet="true"
                msdata:MainDataTable="Version"
                msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:element name="Versions">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Version">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Edits">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="Edit">
                          <xs:complexType>
                            <xs:attribute name="Content" type="xs:string" />
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
                <xs:attribute name="Id" type="xs:string" />
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
      </xs:element>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Versions>
    <Version Id="1.0.5 - Coming next!">
      <Edits>
        <Edit Content="Bla bla 1" />
        <Edit Content="Bla bla bla" />
      </Edits>
    </Version>
    <Version Id="1.0.4 - Coming soon!">
      <Edits>
        <Edit Content="First edit of the version" />
        <Edit Content="Second edit of the version" />
      </Edits>
    </Version>
  </Versions>
</ChangeHistory>

此XML是从.NET数据集生成的,我认为问题出在元素内部(因此外部部分是正确的!):

<xs:schema id="ChangeHistory"
    xmlns=""
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

VersionEdit元素的所有属性都是
xs:string
类型


非常感谢您的帮助。

只需使用Visual Studio 20120 XSD工具生成的此模式即可:

<xs:schema id="ChangeHistory"
         xmlns=""
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ChangeHistory"
            msdata:IsDataSet="true"
            msdata:MainDataTable="Version"
            msdata:UseCurrentLocale="true">
  <xs:complexType>
    <xs:choice minOccurs="0"
               maxOccurs="unbounded">
      <xs:element name="Versions">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Version"
                        minOccurs="0"
                        maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Edits"
                              minOccurs="0"
                              maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="Edit"
                                    minOccurs="0"
                                    maxOccurs="unbounded">
                          <xs:complexType>
                            <xs:attribute name="Content"
                                          type="xs:string" />
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
                <xs:attribute name="Id"
                              type="xs:string" />
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>
</xs:element>


嗯,为什么您的XML和模式在同一个文档中?因为这是作为我的项目的本地化资源加载的XML,Visual Studio可以在编译期间验证我的XML…如果我指定了正确的模式!我在模式中看不到元素编辑…是的,这是真的:我在处理上面的元素…我想如果我解决了版本元素问题,我可以处理这个问题!伙计,你的版本和编辑元素都没有出现在模式中,这就是事情失败的原因。我不是说版本和编辑标签。