2012-01-06 13 views
0

機能戻り値の型の問題

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であり、型なしではありません。問題がどこにある 私は...私はサクソンEEと酸素13.0を使用しています

を得ることはありません9.3.0.5

+0

エラーが{http://www.w3.org/2001/XMLSchema}untyped、私がhttp://www.w3を持っている間に記述しているので、タイプが探しているように見えます。 org/2001/XMLSchema-instance しかし、どの属性が期待していますか? declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; declare namespace xs = "http://www.w3.org/2001/XMLSchema"; – AleIla

答えて

1

サクソンは、すべての直接構築され、ここで確かに正しいです(「インライン」)の要素はタイプを持っていますxs:untyped(または、コンストラクションモードが保存に設定されている場合はxs:anyType)。

要素がスキーマに対して検証されるまで、xsi:type要素は無意味です。これを行う最も簡単な方法は、検証式で要素をラップすることです:

:あなたが実際に xsi:type属性を必要としない場合のXQuery 3.0で、その後、あなたが特定の型としての要素を検証できることを

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" /> } 
}; 

は注意

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 /> } 
};