【发布时间】:2012-08-26 10:29:23
【问题描述】:
我在写下我的 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">
Version和Edit元素的所有属性都是xs:string类型。
任何帮助将不胜感激,谢谢。
【问题讨论】:
-
呃,为什么你的 XML 和架构在同一个文档中?
-
因为这是作为我项目的本地化资源加载的 XML,并且 Visual Studio 可以在编译期间验证我的 XML...如果我指定了正确的架构!
-
我没有在架构中看到元素编辑...
-
是的,这是真的:我在搞乱上层元素......我想如果我解决了版本元素问题,我可以解决这个问题!
-
伙计,您的 Versions 和 Edits 元素都没有出现在架构中,这就是事情失败的原因。我不是指版本和编辑标签。
标签: xml validation schema