【发布时间】:2012-02-14 09:25:45
【问题描述】:
我在使用 c# XDocument XSD 验证时遇到问题。
Xml Spy 对以下文件进行了很好的验证,但 .Net (c#) 对以下文件进行了很好的验证
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Simple.xsd">
<Var Name="$Toto"/>
</Root>
架构
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="Var">
<xs:complexType>
<xs:attribute name="Name" type="ST_VariableIdentifier" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="ST_VariableIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="$[a-z,A-Z]*"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
一个想法?
【问题讨论】:
-
这会受益于 C# 标签吗?
-
这是 C# 中的一个错误,有一个解决方法:使用 [$]。不要费心尝试诸如字符引用之类的东西,例如$ ,由于某种原因,C#在这里很挑剔...
标签: validation xsd design-patterns