From: Matt Gushee Date: 2002-10-01T02:20:21+09:00 Subject: Re: REXML namespace support On Mon, Sep 30, 2002 at 11:08:15PM +0900, Bob Hutchison wrote: > On 9/27/02 11:18 AM, "Volkmann, Mark" wrote: > > > In my case I'm given a string which is a namespace prefix and I want to > > determine the namespace it is associated with. I don't have an Element object > > so I can't use the namespace method. > > XML namespaces are defined as xml is processed. The prefix may be reused. You mean 'prefix-to-namespace mappings are defined ...', don't you? Sorry to be picky, but XML namespaces are confusing enough without imprecise explanations. > > > > > is legal (though a questionable practice, and ignoring opinions w.r.t. > Namespaces being URLs). In this example there are two namespaces but only > one prefix is used. In general, the prefix mapping to namespace is scoped. > This makes it impossible to answer the question you want to ask unless you > can identify a spot in the document. I would say 'unreliable' rather than 'impossible'. You're quite right that it's legal to reuse prefixes, but it would be very counterintuitive to do so, and I doubt that it's likely to happen in practice; I've certainly never seen it (except in examples contrived to show that it can be done). Have you? Which means that, if a certain degree of doubt is acceptable (e.g. doing a first-pass analysis of a large collection of XML documents, with thorough testing to take place later), there shouldn't be a problem with just pulling out the first available mapping (though I don't think I'd choose that approach myself unless I were under extreme time pressure). It might be interesting to hear more about the problem the original poster was trying to solve. But he seems to have either given up, or been satisfied with the answers he got and wandered off without bothering to say "thanks." Oh, well. That's mailing-list life. > I know that the parser I wrote for ruby will supply you all in-scope > prefix-namespace mappings as it parses an XML file. I assume that REXML will > do the same, though I don't know for sure. Yes, it will. -- Matt Gushee Englewood, Colorado, USA mgushee@havenrock.com http://www.havenrock.com/