Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi Raghu, Give use some sample XML file and your existing code sample to understand the scenario . Thanks and regards Raja From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Raghu Sent: Wednesday, July 22, 2015 4:27 PM To: MarkLogic Developer Discussion Cc: Naga . Subject: Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix I understand the concept of namespace and we are allowed to have different namespaces inside a single xml apart from the root namespace, IMHO any element unless specified otherwise, inherits it's parent's namespace. My question is that is there a way where I apply the xpath on a child element, and ignore/remove the unused namespace prefix from the resulting xml? One of my dependent service is consuming the xml and although, what I'm returning to that service is semantically the same as what was saved, these unused prefixes are creating an issue. Any help is appreciated. On Tue, Jul 21, 2015 at 1:30 PM, Asit Nautiyal asitnauti...@outlook.commailto:asitnauti...@outlook.com wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.comhttp://anywhere.anything.com/ , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.commailto:raghupathy.visweswa...@gmail.com To: general@developer.marklogic.commailto:general@developer.marklogic.com CC: nagendran...@gmail.commailto:nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.commailto:General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.commailto:General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored. ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
I understand the concept of namespace and we are allowed to have different namespaces inside a single xml apart from the root namespace, IMHO any element unless specified otherwise, inherits it's parent's namespace. My question is that is there a way where I apply the xpath on a child element, and ignore/remove the unused namespace prefix from the resulting xml? One of my dependent service is consuming the xml and although, what I'm returning to that service is semantically the same as what was saved, these unused prefixes are creating an issue. Any help is appreciated. On Tue, Jul 21, 2015 at 1:30 PM, Asit Nautiyal asitnauti...@outlook.com wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal -- Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns= http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi, Let's consider a simplified version of your code: ns:root xmlns:ns=one child xmlns=two/ /ns:root/* It is important to understand that the namespace one, bound to the prefix ns, is in scope for the element 'child'. It is not because the element name does not use that perfix that it should disappear from the XDM instance. What if it used in a value, like the following (think about XML Schema e.g.): ns:root xmlns:ns=one child xmlns=two unit=ns:mile/ /ns:root/* The behaviour you see, is the one required by the XQuery recommendation. And it should not harm. If you really want to get rid of that namespace binding, you can 1) make a recursive descent transform, copying every element, copying only the namespace bindings actually used in an element or attribute name, or 2) make sure that all unused namespace bindings from ancestors are hidden, by reusing the same prefix (or default namespace): root xmlns=one child xmlns=two/ /root/* Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 21 July 2015 at 17:07, Raghu wrote: HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi, Just to make it clear, there is nothing wrong with using several namespaces in the same document. Namespaces have been invented to differentiate names (by creating uniquely identified spaces for them). So their unit of application is element and attribute names, rather than documents. Think for instance about embedding SVG and MathML elements in a XHTML or XSL-FO document. The namespaces will ensure that elements with the (local) name title can be differentiated, by looking at within what namespace they have been defined. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 21 July 2015 at 19:30, Asit Nautiyal wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Thanks Florent Georges! On Wed, Jul 22, 2015 at 7:42 AM, Florent Georges li...@fgeorges.org wrote: Hi, Just to make it clear, there is nothing wrong with using several namespaces in the same document. Namespaces have been invented to differentiate names (by creating uniquely identified spaces for them). So their unit of application is element and attribute names, rather than documents. Think for instance about embedding SVG and MathML elements in a XHTML or XSL-FO document. The namespaces will ensure that elements with the (local) name title can be differentiated, by looking at within what namespace they have been defined. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 21 July 2015 at 19:30, Asit Nautiyal wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi, This should work indeed, as a descent recursive copy. Given there is no attribute at all in the element to return. A couple of comments though: - there is no document node involved in this example, but if you match the case in the function, the most sensible thing to do is to create a document node in the copy as well - in XDM, a document node can have several children, elements and other nodes as well, here you selecting only the first element - matching explicitly the cases for PIs and comment nodes does not make more sense, especially when not handling text nodes explicitly So I guess this one version would be more reusable: declare function local:copy-tree($node as node()) as node() { typeswitch($node) (: create a document node and recurse :) case document-node() return document { $node/node() ! local:copy-tree(.) } (: create an element node, copy attributes, and recurse :) case element() return element { fn:node-name($node) } { $node/@*, $node/node() ! local:copy-tree(.) } (: return $node as is, will be copied when added to another parent :) default return $node }; PS: Not tested. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 22 July 2015 at 15:16, Indrajeet Verma wrote: Hi Raghu, Can you try this and see if works for you? declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); declare function local:reparse-doc($node) { typeswitch($node) case document-node() return local:reparse-doc($node/*[1]) case element() return element { fn:node-name($node) } { $node/node() ! local:reparse-doc(.) } case processing-instruction() return $node case comment() return $node default return $node }; let $doc := doc(/text.xml)//*:child return local:reparse-doc($doc) Regards, Indy On Wed, Jul 22, 2015 at 6:28 PM, Raghu raghupathy.visweswa...@gmail.com wrote: Thanks Florent Georges! On Wed, Jul 22, 2015 at 7:42 AM, Florent Georges li...@fgeorges.org wrote: Hi, Just to make it clear, there is nothing wrong with using several namespaces in the same document. Namespaces have been invented to differentiate names (by creating uniquely identified spaces for them). So their unit of application is element and attribute names, rather than documents. Think for instance about embedding SVG and MathML elements in a XHTML or XSL-FO document. The namespaces will ensure that elements with the (local) name title can be differentiated, by looking at within what namespace they have been defined. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 21 July 2015 at 19:30, Asit Nautiyal wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi Raghu, Can you try this and see if works for you? declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); declare function local:reparse-doc($node) { typeswitch($node) case document-node() return local:reparse-doc($node/*[1]) case element() return element { fn:node-name($node) } { $node/node() ! local:reparse-doc(.) } case processing-instruction() return $node case comment() return $node default return $node }; let $doc := doc(/text.xml)//*:child return local:reparse-doc($doc) Regards, Indy On Wed, Jul 22, 2015 at 6:28 PM, Raghu raghupathy.visweswa...@gmail.com wrote: Thanks Florent Georges! On Wed, Jul 22, 2015 at 7:42 AM, Florent Georges li...@fgeorges.org wrote: Hi, Just to make it clear, there is nothing wrong with using several namespaces in the same document. Namespaces have been invented to differentiate names (by creating uniquely identified spaces for them). So their unit of application is element and attribute names, rather than documents. Think for instance about embedding SVG and MathML elements in a XHTML or XSL-FO document. The namespaces will ensure that elements with the (local) name title can be differentiated, by looking at within what namespace they have been defined. Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 21 July 2015 at 19:30, Asit Nautiyal wrote: Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards, Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;; xdmp:document-insert ( /text.xml, ns:root child xmlns=http://anywhere.anything.com;/child /ns:root ); doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance! Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] Need to remove unused xml namespace prefix
Hi Raghu, Here you want to keep the text.xml as part of http://somewhere.something.com; namespace and want to make its child element (child) part to other namespace http://anywhere.anything.com; , correct me, if I am wrong! If this is the case then, you are making this xml file as ambiguous. In xml file , all child elements should belongs to same namespace as its root element, that's why we have concept of namespace. Regards,Asit Nautiyal Date: Tue, 21 Jul 2015 11:07:53 -0400 From: raghupathy.visweswa...@gmail.com To: general@developer.marklogic.com CC: nagendran...@gmail.com Subject: [MarkLogic Dev General] Need to remove unused xml namespace prefix HI All, The following snippet gives me the unused namespace prefix (in this case ns), I need to ignore such unused namespace prefixes in the output Query declare namespace ns=http://somewhere.something.com;xdmp:document-insert(/text.xml,ns:rootchild xmlns=http://anywhere.anything.com;/child/ns:root);doc(/text.xml)//*:child Result child xmlns:ns=http://somewhere.something.com; xmlns=http://anywhere.anything.com/ Thanks in advance!Raghu ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general