If you put all the possible namespace declarations on the root element they 
wont repeat in child elements.  like this


xquery version "1.0-ml";
declare namespace ns1="http://mycompany.com/hello/1";;
declare namespace ns2="http://mycompany.com/hi/2";;
declare namespace ns3="http://mycompany.com/data/3";;

<ns1:row xmlns:ns2="http://mycompany.com/hi/2"; 
xmlns:ns3="http://mycompany.com/data/3";>
{for $out in 1 to 3 return 
   element ns2:column {
       element ns3:data{string("I am that I am")}}
}
</ns1:row>

==

<?xml version="1.0" encoding="UTF-8"?>
<ns1:row xmlns:ns2="http://mycompany.com/hi/2"; 
xmlns:ns3="http://mycompany.com/data/3"; 
xmlns:ns1="http://mycompany.com/hello/1";>
  <ns2:column>
    <ns3:data>I am that I am</ns3:data>
  </ns2:column>
  <ns2:column>
    <ns3:data>I am that I am</ns3:data>
  </ns2:column>
  <ns2:column>
    <ns3:data>I am that I am</ns3:data>
  </ns2:column>
</ns1:row>


-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 650-287-2531
Cell:  +1 812-630-7622
www.marklogic.com

This e-mail and any accompanying attachments are confidential. The information 
is intended solely for the use of the individual to whom it is addressed. Any 
review, disclosure, copying, distribution, or use of this e-mail communication 
by others is strictly prohibited. If you are not the intended recipient, please 
notify us immediately by returning this message to the sender and delete all 
copies. Thank you for your cooperation.


> -----Original Message-----
> From: [email protected] [mailto:general-
> [email protected]] On Behalf Of Vedavalli Radhika
> Sent: Friday, April 20, 2012 7:42 AM
> To: General Mark Logic Developer Discussion
> Subject: [MarkLogic Dev General] Create new element - Namespace appear in
> each and every element
> 
> When I create elements using xquery along with the namespace label, It
> is defining the namespace local in all the elements, can we have it
> defined once at the top of the doc and use the labels throughout?  Or
> is that something MarkLogic doesn't do easily?  It would cut down the
> size of the document by more than half.
> 
> I have given a sample code which explains the problem. For a huge xml,
> the data really looks clumsy and gets heavier.
> 
> Code snippet:
> declare namespace ns1="http://mycompany.com/hello/1";;
> declare namespace ns2="http://mycompany.com/hi/2";;
> declare namespace ns3="http://mycompany.com/data/3";;
> 
> element ns1:row
> {for $out in $results
>    element ns2:column
>        element ns3:data{string("I am that I am")}
> }
> 
> For the above code snippet in my xquery, the response got is as below:
> <ns1:row xmlns:ns1="http://mycompany.com/hello/1";>
> <ns2:column xmlns:ns2="http://mycompany.com/hi/2";>
> <ns3:data xmlns:ns3="http://mycompany.com/data/3";>I am that I am
> 1</ns3:data>
> </ns2:column>
> <ns2:column xmlns:ns2="http://mycompany.com/hi/2";>
> <ns3:data xmlns:ns3="http://mycompany.com/data/3";>I am that I am
> 2</ns3:data>
> </ns2:column>
> </ns1:row>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to