具有特定名称空间的anyAttribute不起作用 [英] anyAttribute with specific namespace doesn't work
问题描述
你好,我为此浪费了一整天,找不到解决方法.
我有以下主要架构:
hello, i''ve wasted a whole day for this, can''t find the solution.
i have the following main schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Users">
<xs:complexType>
<xs:attribute name="FirstName" type="xs:string" use="optional" />
<xs:anyAttribute namespace="http://www.w3.org/2001/AppLog"/>
</xs:complexType>
</xs:element>
</xs:schema>
我想使用"anyAttribute"从特定架构中获取属性,因此我声明了该二级架构:
i want to use the "anyAttribute" to get an attribute from a specific schema, so i declared this secondary schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/2001/AppLog">
<xs:attribute name="SystemUsers" type="xs:string" default="abc"/>
</xs:schema>
然后,我尝试针对此xml验证架构:
then, i tried to validate the schema against this xml:
<br />
<Users UserPreferencesSafe=""abcd"" SystemUsers=""abc""/><br />
我通过将2个模式添加到模式集(XMLSchemaSet.Add)来做到这一点,
然后我将XMLDocument.Validate与此模式集一起使用.
我得到:
验证引发错误:不允许使用"SystemUsers"属性.
顺便说一句,如果我使用anyAttribute namespace ="## any",并添加2个有效的模式.但我需要具体说明.
我想念什么?
i do it with adding the 2 schemas to the schema set (XMLSchemaSet.Add),
then i use the XMLDocument.Validate with this schema set.
i get:
The validation raised a error:The ''SystemUsers'' attribute is not allowed.
by the way, if i use anyAttribute namespace="##any", and add the 2 schemas it works. but i need to be specific.
what am i missing?
thanks.
推荐答案
您似乎误用了complexType
:如果没有中间XSD节点描述复杂类型内容的类型,您就不能指定复杂类型的内容,例如sequence
,如本例所示:
It looks like you misusecomplexType
: you cannot specify content of complex type without intermediate XSD node describing the type of complex type content, such assequence
, like in this example:
<xs:element name="ExistingRecord">
<xs:complexType>
<xs:sequence>
<xs:element name="ExistingFieldElement" type="xs:string" />
</xs:sequence>
<xs:anyAttribute />
</xs:complexType>
</xs:element>
此示例摘自 http://msdn.microsoft.com/en-us/library/aa562055.aspx [ ^ ].
我不确定这是否是唯一的问题,但这是第一个引起我注意的问题.
This example is extracted from http://msdn.microsoft.com/en-us/library/aa562055.aspx[^].
I''m not sure if this is the only problem, but this is the first one which caught my eye.
这篇关于具有特定名称空间的anyAttribute不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!