[MarkLogic Dev General] Is there any code available that simply descends through a document node and discovers and prints out the namespace associated with each element?
Tim Meagher
tim at aaom.net
Thu Jun 3 16:58:00 PDT 2010
Looks great - thank you!
Tim
-----Original Message-----
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of G. Ken Holman
Sent: Thursday, June 03, 2010 11:41 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] Is there any code available that simply
descends through a document node and discovers and prints out the namespace
associated with each element?
At 2010-06-03 16:35 -0400, Tim Meagher wrote:
>Ultimately what I'm looking for is a way to automatically discover a
>namespace in any given so that if I want to access it's contents I
>don't have to know the namespace ahead of time,
Not sure what you are saying there.
>but it would be cool to have an app that can descend a document and
>layout the xpath and namespace of each node.
I hope the example below helps. It exposes the complete path of
elements from the document element to each element in the instance.
. . . . . . . . . Ken
~/t $ cat paths.xml
<hello xmlns:abc="urn:X-abc">
<abc:def>
<ghi xmlns="urn:X-ghi"/>
</abc:def>
</hello>
~/t $ cat paths.xq
'
',
for $each in doc( 'paths.xml' )//*
return concat( '/',
string-join( $each/ancestor-or-self::*/concat('{',
namespace-uri-for-prefix(substring-before(name(.),':'),.),
'}',local-name(.)),'/'),
'
' )
~/t $ xquery paths.xq
<?xml version="1.0" encoding="UTF-8"?>
/{}hello
/{}hello/{urn:X-abc}def
/{}hello/{urn:X-abc}def/{urn:X-ghi}ghi
~/t $
--
XSLT/XQuery training: after http://XMLPrague.cz 2011-03-28/04-01
Vote for your XML training: http://www.CraneSoftwrights.com/q/i/
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/q/
G. Ken Holman mailto:gkholman at CraneSoftwrights.com
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general
More information about the General
mailing list