Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making XPATH queries against a document w/ namespaces

195 views
Skip to first unread message

Chris R

unread,
May 26, 2006, 10:12:33 PM5/26/06
to
I'm assuming that this is fairly simple, but I'm a bit new to XML in
general, so I'd like it if someone could baby-step me through the how
of this:

We have a document schema whose instances will refer to three namespaces.

I need to be able to do xpath queries on instances of this document,
knowing only that it matches the schema, but not, for example, what the
namespace prefixes of the elements are.

Consider:
xmlns:a="http://ns1"
xmlns:b="http://ns2"
xmlns:c="http://ns3"

<a:top>
<b:something>
<c:foo bar="baz" />
</b:something>
<a:top>

Suppose I get an instance of this document, but I have no idea what
prefixes map to which namespaces. I can use TclXML/TclDOM to parse it,
but I have no idea whatsoever about how I associate, say, "ns1" with
the namespace "http://ns1" for xpath queries.

Can someone tell me how to do this?

mail address above is accurate, barring the interleaved spam.

Ramon Ribó

unread,
May 27, 2006, 9:08:26 AM5/27/06
to

If you use tdom, instead of tclxml, the query should be
similar to:

set ns { svg http://www.w3.org/2000/svg }
set svgNode [$root selectNodes -namespaces $ns /*/svg:svg|/svg:svg]

Ramon Ribó

En Sat, 27 May 2006 04:12:33 +0200, Chris R <osfpf...@offlineblog.com>
escribió:

--
Compass Ing. y Sistemas Dr. Ramon Ribo
http://www.compassis.com ram...@compassis.com
c/ Tuset, 8 7-2 tel. +34 93 218 19 89
08006 Barcelona, Spain fax. +34 93 396 97 46

Chris Rose

unread,
May 27, 2006, 11:13:31 AM5/27/06
to

That sounds promising. I'll check that one out, too.

I am somewhat constrained by our existing support for TclXML, though;
I'd be pleased if there were a similar mechanism in place for that
module.

Anyone?
--
Chris R
=======
Not to be taken literally, internally, or seriously

e-mail is accurate, barring the interleaved spam.

Steve Ball

unread,
May 28, 2006, 8:21:31 PM5/28/06
to
Chris,

Your later post has shown that you have discovered that TclDOM does
indeed have this facility.

Basically, you must declare the equivalent of the XML Namespace
declarations in the XPath call. The TclDOM selectNodes command accepts
the "-namespaces" option for this purpose (bugs notwithstanding ;-)

Cheers,
Steve Ball

0 new messages