Subject:xQuery 1.0 Produces XPTY0004 Error Author:Ethan Stein Date:10 Jun 2009 04:00 PM Originally Posted: 10 Jun 2009 03:53 PM
When I try to run the below xquery from the command line using xquery 1.0, I get the following error
[XQuery][err:XPTY0004]Required item type of first argument of local:replaceNode() is element(*, xs:untyped); supplied value has item type element(PlanID)
My goal is to replace a specific node with three nodes. I can run it from Stylus Studio 2007 R2 without any problem, but from a command line, it produces the above error.
declare function local:replaceNode($n as element(*, xs:untyped))
{
if (starts-with(upper-case(local-name($n)), "PLANNAME") and (not(ends-with(local-name($n),"Cover"))) and (not(ends-with(local-name($n),"TableHeader"))) and (not(ends-with(local-name($n),"BodyText")))) then local:addPlanName($n)
else (
element { name($n) } {$n/@*,
($n/text(),
for $child in $n/*
return local:replaceNode($child))}
)
};
<ExtractData>
{
for $CurrentYearPlan in $xPRSXMLInput/ExtractData/CurrentYearPlan
return
local:replaceNode($CurrentYearPlan)
}
</ExtractData>
And a sample XML input for xPRSXMLInput is a file containing:
Hi,
the errors seems to point to the fact that the document you are feeding to the command line version of DDXQ is being schema-validated, and cannot match the signature of a function that expects and untyped DOM tree.
One option is to make the XML untyped by removing the xsi:noNamespaceSchemaLocation attribute from the root; the other option is to change the way you invoke DDXQ so that it doesn't attempt schema validation upon binding the external variable.