We are attempting to insert some new elements with attributes into an XML document from a string. The elements have a name space prefix such as asy:
If I use an external variable containing XML to perform a node insert
example :-
declare namespace asy="http://xml.acme.com/asy";
declare variable $part external;
insert nodes $part as first into db:open("PARTDB")/asy:assembly[@name="ZB09010"]
The characters in the xs:string $path reserved for XML e.g. < > etc are converted to < > etc and the insert silently fails.
if I change the insert statement to :
insert nodes fn:parse-xml($part) as first into db:open("PARTDB")/asy:assembly[@name="ZB09010"]
I get the message
FODC0006 (Line 1): The prefix "asy" for element "asy:part" is not bound.
If I add
declare namespace asy="http://xml.acme.com/asy";
at the beginning of the $path variable contents before the XML I get
FODC0006 (Line 1): Content is not allowed in prolog.
If I then change the statement to :
insert nodes xquery:eval($part) as first into db:open("PARTDB")/asy:assembly[@name="ZB09010"]
The insert works as expected.
Note that if the same XML is defined within the query using
let $path := < new xml stuff >
The insert works fine just using $path with no functions applied.
Is this behavior correct and is using xquery:eval($part) the right approach or am I just lucky it works and I should have been doing something different?
Thanks for any insight you can offer.