logo       

RE: Newbie Q: Namespace Handling: msg#00007

Subject: RE: Newbie Q: Namespace Handling
For anyone tracking this down the road, the W3C bugzilla entry is:
http://www.w3.org/Bugs/Public/show_bug.cgi?id=4523

Ken Sall
SAIC > ASC > RDEC > Columbia

-----Original Message-----
From: Sall, Kenneth B. 
Sent: Wednesday, May 02, 2007 6:54 PM
To: Michael Kay; talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
Subject: RE: [xquery-talk] Newbie Q: Namespace Handling

Thank you, Michael. I will submit this to W3C. 

Meanwhile, I tried revising the basic KML (Google Earth) example at 
http://code.google.com/apis/kml/documentation/kml_tut.html#basic_kml
to use a namespace prefix, like so:

<?xml version="1.0" encoding="UTF-8"?>
<ge:kml xmlns:ge="http://earth.google.com/kml/2.1";>
   <ge:Folder>
      <ge:Placemark>
         <ge:name>Simple placemark</ge:name>
         <ge:description>Attached to the ground. Intelligently places itself 
       at the height of the underlying terrain.
                </ge:description>
         <ge:Point>
                        
<ge:coordinates>-122.0822035425683,37.42228990140251,0</ge:coordinates>
         </ge:Point>
      </ge:Placemark>
   </ge:Folder>
</ge:kml>


Surprisingly, Google Earth thinks the root <kml> element is "missing or bad"! 
I'll try the other options you've suggested, especially (c).

Ken Sall

-----Original Message-----
From: Michael Kay [mailto:mike-JkSD5nQpfvpWk0Htik3J/w@xxxxxxxxxxxxxxxx] 
Sent: Wednesday, May 02, 2007 6:18 PM
To: Sall, Kenneth B.; talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
Subject: RE: [xquery-talk] Newbie Q: Namespace Handling


When you do 

<kml xmlns="http://earth.google.com/kml/2.1";>

the default namespace declaration affects the contained path expressions, so
in

doc("namespace.xml")//bar

you are selecting bar elements in namespace http://earth.google.com/kml/2.1

There's a good reason XQuery was done this way, it was an attempt to avoid
the problems that people have with default namespace handling in XSLT 1.0,
where a default namespace declaration *doesn't* affect unprefixed names in
path expressions. But it makes it very difficult to handle your scenario,
where the source document is in no namespace but you want result elements to
be in a default (unprefixed) namespace. In fact it's because of this
scenario that XSLT 1.0 was designed the way it was...

I think this is a serious usability problem with XQuery 1.0 as defined and
it needs to be addressed in XQuery 1.1. (Please feel free to file this as a
comment against the spec - they carry more weight when they come from
users.)

In the meantime, I think your best option is probably to avoid using the
default namespace in the result document: use a prefixed namespace instead.
If you really need the result document to use the default namespace, then
postprocess it to change the prefix. 

If you can't do that, some other possible workarounds are:

(a) put the contained query 

    for $i in doc("namespace.xml")//bar return $i 

into a function or a variable where the namespace context can be different

(b) use doc("namespace.xml")//*:bar

which will select elements with local name "bar" in any namespace or none

(c) generate the output elements with a computed element constructor

element {xs:QName("kml")}{
  element {xs:QName("Folder"){ {
    ... etc ...

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: talk-bounces-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx 
> [mailto:talk-bounces-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx] On Behalf Of 
> Sall, Kenneth B.
> Sent: 02 May 2007 22:52
> To: talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
> Subject: [xquery-talk] Newbie Q: Namespace Handling
> 
> Hello all.
> 
> I've having difficulty outputting the correct default 
> namespace from a query. I'm using SaxonB 8.9J on Windows XP 
> with jre 1.6.0_01.
> 
> With this trivial input:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <bar>foobar</bar>
> 
> and trivial XQuery #1:
> 
> <kml>
>   <Folder>
>       {
>       for $i in doc("namespace.xml")//bar
>       return $i
>       }
>   </Folder>
> </kml>
> 
> I get the result #1:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <kml>
>    <Folder>
>       <bar>foobar</bar>
>    </Folder>
> </kml>
> 
> However, I want the opening <kml> to appear as:
> 
> <kml xmlns="http://earth.google.com/kml/2.1";>
> 
> With XQuery #2:
> 
> <kml xmlns="http://earth.google.com/kml/2.1";>
>   <Folder>
>       {
>       for $i in doc("namespace.xml")//bar
>       return $i
>       }
>   </Folder>
> </kml>
> 
> I get result #2:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.1";>
>    <Folder/>
> </kml>
> 
> Which isn't correct for the <Folder> content.
> 
> I've also tried adding a default namespace declaration to XQuery #2:
> 
> declare default element namespace "http://earth.google.com/kml/2.1";;
> 
> but that has no impact; I still get result #2.
> 
> What am I missing? Thanks in advance for any clarification 
> about namespace handling.
> 
> Kenneth B. Sall
> XML Data and Systems Analyst
> Advanced Systems and Concepts
> Science Applications International Corp. (SAIC)
> 7125 Columbia Gateway Dr., Suite 250
> Columbia, MD  21046
> 410-953-7016 (office)
> 410-300-2997 (mobile)
> 
> _______________________________________________
> talk-9zRdbLeNGsRBDgjK7y7TUQ@xxxxxxxxxxxxxxxx
> http://x-query.com/mailman/listinfo/talk



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
region.costa-ri...    user-groups.lin...    lang.prothon.us...    xfree86.cvs/200...    finance.aqbanki...    ietf.smtp/1993-...    web.turbogears....    jakarta.cactus....    yellowdog.gener...    php.gtk+.genera...    org.region.indo...    hurd.l4/2005-10...    culture.religio...    apple.fink.gene...    db.mysql.window...    bluez.devel/200...    security.pgp-ba...    video.blender.d...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe