One way you can get this is to recursively walk the XML document,
printing out the name of the elements and attributes along the way.
Then take the distinct-values of your resulting transformation.  Here is
some simple code that does that with your sample data:

xquery version "1.0-ml";
declare function local:passthru($x as item()) as item()* {
  for $z in $x/(@* | node()) return local:dispatch($z)};

declare function local:dispatch($x as node()) as item()* {
typeswitch ($x)
  case text() return $x
  case element()  return (fn:local-name($x), local:passthru($x))
  case attribute() return (fn:local-name($x), local:passthru($x))
  default return <temp>{local:passthru($x)}</temp>
};

let $node := 
<books>
  <book price="10.23" >
    <para id="1"/> 
    <para id="2"/>
  </book>
  <book price="10.23" >
   <para id="1"/>
   <para title="name"/>
  </book>
</books>
return
fn:distinct-values(local:dispatch($node))

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
NvoiceMarklogic
Sent: Wednesday, December 03, 2008 9:17 PM
To: [email protected]
Subject: [MarkLogic Dev General] i want to display attributes under
elementname

How to display every unique, element, attribute, and value of a xml?
Basically I want to display  distinct attributes and values of an
element.


ex:

<books>
<book price="10.23" >
<para id="1">
.
.
.
</para>
<para id="2">


.
.
.
</para>
</book>

<book price="10.23" >
<para id="1">
.
.
.
</para>
<para title="name">
.
.
.
</para>
</book>
</books>

 output should be:

book
price


para
id
title
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to