users@jaxb.java.net

JAXB XML and Oracle extracts

From: William Saxton <saxton_at_gmail.com>
Date: Wed, 23 May 2007 11:22:26 -0400

Hi all,

  This may be more of an Oracle question, but I figured people from here
have probably dealt with this before so...

  I have some JAXB generated XML stored in Oracle as an XMLTYPE.

select inventory_xml from unix_system;

INVENTORY_XML
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="US-ASCII" standalone='yes'?>
<server xmlns="http://www.namespace.com/sample">
  <hostname>foo</hostname>
.
.
.

  This does not work:

SQL> select u.inventory_xml.extract('/server/hostname').getStringVal() from
unix_system u

no rows selected

  This works:

SQL> select u.inventory_xml.extract('/x:server/x:hostname','xmlns:x="
http://www.namespace.com/sample"').getStringVal() from unix_system u

U.INVENTORY_XML.EXTRACT('/X:SERVER/X:HOSTNAME','XMLNS:X="
HTTP://WWW.NAMESPACE.COM/SAMPLE
--------------------------------------------------------------------------------
<hostname xmlns="http://www.namespace.com/sample">foo</hostname>

-------

  Is there something I can do in my Oracle query (OR in my JAXB created XML)
that will allow me to do the first, more simple, query? The second way
seems a bit more hackish, as I have to hard-code the namespace in my oracle
queries, using a random prefix.

-Bill