[xquery-talk] Newbie Q: Namespace Handling

Sall, Kenneth B. KENNETH.B.SALL at saic.com
Wed May 2 18:52:21 PDT 2007


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)



More information about the talk mailing list