Re: [xml] Namespace Handling



Hi

Balint Joo wrote:
>     I think I understand now.

I'm sorry but that's not yet the case.

> While in the document we
> have one prefix,

... or many different ones all representing the same namespace name.

> the query can have a completely different one,
> as long as they both map to the same target namespace.

You simply match the elements and attributes in their proper namespaces.

> The document
> namespace declarations map tags to one namespace.

No, they either map prefixes to namespace names or the declare default namespacs.

> They are not
> instructions for the XPath processor to be registered.

But yes, the XML parser must honor them and pass the namespace info on to the XPath processor; otherwise it couldn't know about the namespaces declared in the document.

> I as a
> querier, if I want to make a namespace prefixed query, have
> to define their namespaces and my own prefix (which may or may not be
> the same as the original ones). Then I query  with my prefix.

pretty much

(in XSLT 2 you can also supply a default namespace thus match namespaced objects without using any prefixes in the XPath expression)

> so for my last example (sent offlist)
>
> <foo>
>     <bar stool="barstool">
>         <stool:interesting/>
>         </bar>
> </foo>

As I replied to you offlist:

Prefix "stool" is not declared, so the document can not be processed by a parser supporting XML namespaces.

In order to prevent many more misunderstandings, may I kindly suggest to RTFM:
http://www.w3.org/TR/REC-xml-names/

> I myself as the querier have to  reqister namespace prefix "q" with
> namespace
> target "barstool" and then perform XPath queries a la:
>
> //q:interesting

yes, for example, you're free to choose the prefix, eg

First declare the namespace
  xmlns:bs="barstool"
  (or a different syntax for supplying the namespace name
  for the prefix to the XPath processor)
then do
 //bs:interesting
and match
  <interesting xmlns="barstool"/>
and
  <foo:interesting xmlns:foo="barstool"/>
and
  <blammo xmlns="barstool">
    <interesting/>
  </blammo>
etc

See XSLT for example.

Tobi

--
http://www.pinkjuice.com/











[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]