I'm trying to clean up some old code of ours that is throwing server errors when fed buggy data. To simplify greatly, the code is something like this:

let $element := <el att1="one" att2="two">text</el>
return element new {
  $element/attribute(),
  attribute id { "new-id" },
  $element/node()
  }

where the content of $element comes from XML data where <el> is not supposed to carry an @id attribute. Of course if the data is buggy and $element has a child @id, the above code throws a dynamic error (XQDY0025, duplicate attribute names).

I naively thought this might be a quick fix to prevent runtime errors:

xquery version "3.0";
let $element := <el att1="one" att2="two" id="old-id">text</el>
return element new {
  $element/attribute(),
  try {attribute id { "new-id" }} catch * {()},
  $element/node()
  }

but it doesn't trap the error (in any XQuery 3 processor I've checked). The try/catch will work only if put around the entire element constructor.

Can someone who understands the 3.0 spec better than I do explain the general principle behind this? Is it that the processor cannot be expected to evaluate the legality of the constructed element until all its parts have been assembled?

David

--
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville, VA 22904-4314 USA
Email: [email protected]   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to