XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ethan SteinSubject: 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.

My xquery is

declare option ddtek:xml-streaming 'yes';
declare option ddtek:serialize "indent=yes, omit-xml-declaration=no";

declare variable $xPRSXMLInput as document-node(element(*, xs:untyped)) external;

declare function local:addPlanName($planNameNode as element(*, xs:untyped))
{

let $nodeName := name($planNameNode)
let $coverNode := concat($nodeName, "Cover")
let $tableHeaderNode := concat($nodeName, "TableHeader")
let $bodyTextNode := concat($nodeName, "BodyText")
let $planName := $planNameNode/text()
let $planName := fn:replace($planName, "AARP", "AARP®")
let $planName := fn:replace($planName, "MedicareComplete Essential", "MedicareComplete Essential®")
let $planName := fn:replace($planName, "Evercare", "Evercare®")
let $planName := fn:replace($planName, "MedicareComplete Choice", "MedicareComplete Choice®")
let $planName := fn:replace($planName, "Erickson Advantage", "Erickson Advantage®")
let $planName := fn:replace($planName, "SecureHorizons ", "SecureHorizons ®")
let $planName := fn:replace($planName, "MedicareComplete Plus", "MedicareComplete Plus™")
let $planName := fn:replace($planName, "MedicareComplete Value", "MedicareComplete Value™")
let $planName := fn:replace($planName, "MedicareComplete Premier", "MedicareComplete Premier™")
let $planName := fn:replace($planName, "MedicareComplete Balance", "MedicareComplete Balance™")
let $planName := fn:replace($planName, "MedicareComplete Mosaic", "MedicareComplete Mosaic™")
let $planName := fn:replace($planName, "MedicareDirect", "MedicareDirectࡈ")
return
if(fn:contains($planName, "MedicareComplete") and not(fn:contains($planName, "Essential")) and not(fn:contains($planName, "Choice")) and not(fn:contains($planName, "Plus")) and not(fn:contains($planName, "Value")) and not(fn:contains($planName, "Premier")) and not(fn:contains($planName, "Balance")) and not(fn:contains($planName, "Mosaic"))) then
let $planName := fn:replace($planName, "MedicareComplete", "MedicareComplete®")

return (
element { $nodeName } { $planNameNode/text() },
element { $coverNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $tableHeaderNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $bodyTextNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") }
)
else (
element { $nodeName } { $planNameNode/text() },
element { $coverNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $tableHeaderNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") },
element { $bodyTextNode } { concat("<p><span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;">",$planName, "</p>") }
)
};

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:

<ExtractData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:/xPression/CustomerData/Schema/SB3_2.xsd">
<CurrentYearPlan>
<PlanID>H0303015</PlanID>
<ContractNumber>H0303</ContractNumber>
<PBPNumber>015</PBPNumber>
<BusinessSegment>Secure Horizons West</BusinessSegment>
<PlanType>HMO</PlanType>
<PlanDescription>Health Maintenace Organization</PlanDescription>
<SNPFlag>False</SNPFlag>
<PlanName1>&lt;p&gt;&lt;span style="color:#000000;FONT-SIZE: 12pt;font-family:Times;"&gt;AARP MedicareComplete Choice Plan 2&lt;/p&gt;</PlanName1>
<PlanName2>&lt;p&gt;&lt;span style="color:#FFFFFF;FONT-SIZE: 12pt;font-family:Arial;"&gt;&lt;b&gt;AARP MedicareComplete Choice Plan 2&lt;/b&gt;&lt;/p&gt;</PlanName2>
<LegalDescription>PACIFICARE OF ARIZONA, INC</LegalDescription>
<BrandName>AARP</BrandName>
<DrugCoverageType>MAPD</DrugCoverageType>
</CurrentYearPlan>
</ExtractData>

Please note, I do not have the option to upgrade to xQuery 2.0 and use Update Factory functionality. Therefore, recursion is my only option.


Please help.

Postnext
Ethan SteinSubject: xQuery 1.0 Produces XPTY0004 Error
Author: Ethan Stein
Date: 12 Jun 2009 03:57 AM
Here is the specific xQuery I am using:

PRODUCTNAME=DataDirect XQuery
BUILDDATE=Mon Aug 13 16:58:06 CEST 2007
DDXQVERSION=R028302
XQINSTALLER=R028302
SWBE=0032
SWCFG=0001
XQXML=036101
XQEXTRACTOR=029201
XQMEDIATOR=030402
XQXQJ=022702
XQSAXON=/sqlnkdev/releases/XQSAXON/005300
JDK=/sqlnkdev/releases/ext/JDK/0106
STAX=/sqlnkdev/releases/ext_remote/STAX/0100
CONNECTJDBC=/sqlnkdev/releases/ext_remote/ConnectJDBC/030631
MAJORVERSION=3
MINORVERSION=0

Posttop
(Deleted User) Subject: xQuery 1.0 Produces XPTY0004 Error
Author: (Deleted User)
Date: 15 Jun 2009 01:01 PM
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.

Hope this helps,
Alberto

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.