Hi Geert,
Thanks for the info. The thing that helped me most was using the QName function when creating the elements. I thought this would fix a problem I'm having with validating content using a default namespace and schema location, but that's not the case. I could use an example of using marklogic to validate an xml file against a schema where the xml document only contains the default namespace declaration. That includes making sure the schema is configured correctly and that the appropriate declarations exists in the xquery code. The schema is loaded in the Schemas database. Tim -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Geert Josten Sent: Thursday, March 04, 2010 2:13 AM To: General Mark Logic Developer Discussion Subject: RE: [MarkLogic Dev General] Problem inserting default namespaceincreated XML document Hi Tim, That is because you are using computed element constructors, creating list elements explicitly without namespaces (since you pass in the result of a call to local-name()). Also, you should not created xmlns attributes directly, but supply the element constructor with a xs:QName that contains the element name in the desired namespace. I think you are looking for something like this: declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; declare namespace pre = "http://mystuff.com/pre"; declare variable $sd := "http://mystuff.com/schema"; declare function pre:passthru-nodeset($x as node()) as node()* { for $z in $x/(@* | node()) return pre:build-nodeset($z) }; declare function pre:build-nodeset($x as node()) as node()* { (:Revise link counts, clean up link, add link attributes to mixed-citation:) typeswitch ($x) case text() return $x case attribute () return $x case element () return element {QName($sd, local-name($x))} { if (not($x/parent::*)) then attribute xsi:schemaLocation { "/the-schema.xsd" } else (), pre:passthru-nodeset($x) } default return pre:passthru-nodeset($x) }; let $record := <record bla="boo"><list type="unknown"><item/></list></record> return pre:build-nodeset($record) Note: you might be interested in the functions available at http://www.xqueryfunctions.com/xq/. They are included in the distribution of MarkLogic Server 4.1.. Kind regards, Geert > drs. G.P.H. (Geert) Josten Consultant Daidalos BV Hoekeindsehof 1-4 2665 JZ Bleiswijk T +31 (0)10 850 1200 F +31 (0)10 850 1199 mailto:[email protected] http://www.daidalos.nl/ KvK 27164984 P Please consider the environment before printing this mail. De informatie - verzonden in of met dit e-mailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. > From: [email protected] > [mailto:[email protected]] On Behalf Of > Tim Meagher > Sent: donderdag 4 maart 2010 4:43 > To: 'General Mark Logic Developer Discussion' > Subject: [MarkLogic Dev General] Problem inserting default > namespace in created XML document > > Hi Folks, > > > > I'm trying to take an XML document that refers to a DTD and > to remove the DTD declaration and insert a default namespace. > I built a recursive function that goes thru each node: > > > > declare namespace pre = "http://mystuff.com/pre"; > > > > declare function pre:passthru-nodeset($x as node()) as node()* { > for $z in $x/(@* | node()) return pre:build-nodeset($z) }; > > > > declare function pre:build-nodeset($x as node()) as node()* { > (:Revise link counts, clean up link, add link attributes to > mixed-citation:) > typeswitch ($x) > case text() return $x > case attribute () return $x > case element (record) > return > element record { > attribute xsi:schemaLocation { "/the-schema.xsd" }, > attribute xmlns:xsi > {"http://www.w3.org/2001/XMLSchema-instance"}, > attribute xmlns {"http://mystuff.com/schema"}, > pre:passthru-nodeset($x)} > case element () > return element {string(local-name($x))} { > pre:passthru-nodeset($x)} > default return pre:passthru-nodeset($x) }; > > > > The problem is that the resulting XML document from invoking > pre:build-nodeset($record) looks something like this: > > > > <record xsi:schemaLocation="/APAthe-schema.xsd" id="1001" > > xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance > > xmlns="http://mystuff.com/schema"> > <list xmlns=""> > <item> > ... > > > > and when I try to validate the resulting document a > validation error occurs because the default namespace has > been renamed at the <list> element. How can I remove the > xmlns="" declaration from the <list> element? > > > > Thanks ahead of time, > > > > Tim Meagher > > _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
