Learn XQuery |
Home:Learn XQuery: XQuery Tips and Tricks:Extracting Values Why do I get an error trying to extract values from a function returning XML?My XQuery uses a function to access an input XML file: declare function local:input() { When I try to access the result through an XPath expression, I get this error: [DataDirect][XQuery][err:XPTY0019]Error at line 5, column 1. It is a type error if the result of a step (other than the last step) in a path expression contains an atomic value. Can you tell me why? The local:input() function is really meant to return a string, rather than a real XML fragment. Whether or not that's a mistake depends on what you are trying to do. If it's not a mistake, and you really intend for local:input() to reuturn a string containing an XML fragment, then you need to instruct the XQuery processor to parse that string before the XML can be accessed through XPath. You can provide this instruction using the DataDirect XQuery ddtek:parse() function, shown here: declare function local:input() { On the other hand, if the error is that the local:input() function shouldn't be returning a string in the first place — you want a node — the you need to fix the function itself, as shown here: declare function local:input() { Next Question! |
Submit Your DataDirect XQuery Tip or TrickTell us your XQuery Tip or Trick – if it gets published on our site, you’ll receive a |





