As David points out, if a namespace/prefix combination is
defined by an ancestor, you won't see the declaration again
on descendent nodes.  If you had a ns0:table element containing
the rows, you could put all the namespace definitions on it
and you wouldn't see them on the ns1:row elements either.

   Note that this only affects the serialization of the XML,
it makes no significant difference to how the document is
stored in the database.  Each node still has a reference to
its namespace whether that namespace is explicit or implicit
on the element constructor.

   When serializing an element as a string, the namespace must
be accounted for so that a consuming processor knows which
namespace an element belongs to.  As each node is serialized,
if it's namespace/prefix hasn't already been declared in an
ancestor node, it needs to be added to that node.

   Thus, if you have lots of peer nodes in the same namespace
they must all add the declaration during serialization.  But if
a common ancestor has already done so, so that the prefix is
already defined, then it's not necessary to repeat the namespace
definition.

   Again, this doesn't make much difference for how the elements
are stored but can make a big difference in how they are serialized
back to strings.  That can be important if the document needs to be
sent somewhere or read by humans, because it can greatly reduce the
size of the text and make it less cluttered.

   BTW: I hope you're not building an application based on XML
with an SQL-like row/column model.  That is not the way to enoy
the benefits of a native XML database.

On Apr 20, 2012, at 1:33 PM, David Lee wrote:

> 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

---
Ron Hitchens {mailto:[email protected]}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown




_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to