2012-01-06 3 views
0

Согласно w3cфункция возвращает тип вопрос

An ElementTest is used to match an element node by its name and/or type annotation. An ElementTest may take any of the following forms. In these forms, ElementName need not be present in the in-scope element declarations, but TypeName must be present in the in-scope schema types [err:XPST0008]. Note that substitution groups do not affect the semantics of ElementTest. ... element(*, TypeName) matches an element node regardless of its name, if derives-from(AT, TypeName) is true, where AT is the type annotation of the element node, and the nilled property of the node is false.

У меня есть эта функция

import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd"; 
declare function local:matchType(

        $input as element() 

        ) as element(*,cdm-base:ProductComponent..) { 

        <cdm-base:product xsi:type="cdm-base:ProductComponent" /> 


}; 

, который в то время как я печатаю возвращает ошибку:

F [Saxon-EE XQuery 9.3.0.5] Required item type of result of function local:matchType() is element(*, ProductComponent); supplied value has item type element({http://cdm.basic.upc.com}product, {http://www.w3.org/2001/XMLSchema}untyped)

я могу ошибаться, но тип на самом деле cdm-base: ProductComponent и не является нетипизированным. я не получаю, где вопрос ...

Я использую Oxygen 13,0 с саксонской EE 9.3.0.5

+0

Похоже, что тип ищет даже там, потому что ошибка упоминает {http://www.w3.org/2001/XMLSchema}untyped, а у меня есть http: //www.w3. org/2001/XMLSchema-instance Но тогда какой атрибут ожидает? объявить пространство имен xsi = "http://www.w3.org/2001/XMLSchema-instance"; объявить пространство имен xs = "http://www.w3.org/2001/XMLSchema"; – AleIla

ответ

1

Saxon действительно верно здесь, все сразу строится («инлайн») элементы имеют тип xs:untyped (или xs:anyType, если режим построения установлен на сохранение).

Элемент xsi: type не имеет смысла до тех пор, пока элемент не будет проверен на соответствие вашим схемам. Самый простой способ сделать это, чтобы обернуть элемент в выражении валидации:

import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd"; 

declare function local:matchType(
        $input as element()) 
        as element(*,cdm-base:ProductComponent) 
{ 
    validate { <cdm-base:product xsi:type="cdm-base:ProductComponent" /> } 
}; 

Обратите внимание, что в XQuery 3.0, если вы на самом деле не нужен атрибут xsi:type, то вы можете проверить элемент в качестве конкретного типа:

import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd"; 

declare function local:matchType(
        $input as element()) 
        as element(*,cdm-base:ProductComponent) 
{ 
    validate type cdm-base:ProductComponent { <cdm-base:product /> } 
}; 
Смежные вопросы