Hi Greg,

Analyzing this requires a deeper knowledge of xml processing than I can claim. The error is being thrown by org.apache.derby.iapi.types.XML.XMLSerialize() at a point in the code with this comment:

        /* XML serialization rules say that sequence "normalization"
         * must occur before serialization, and normalization dictates
         * that a serialization error must be thrown if the XML value
         * is a sequence with a top-level attribute.  We normalized
         * (and serialized) this XML value when it was first created,
         * and at that time we took note of whether or not there is
         * a top-level attribute.  So throw the error here if needed.
         * See SqlXmlUtil.serializeToString() for more on sequence
         * normalization.
         */

That's all gibberish to me. If you can script the problem and open a JIRA, that would be helpful.

Thanks,
-Rick

On 11/10/15 10:28 AM, Grzegorz Zuber wrote:
Hi,

How to get xml attribute using Apache Derby?

I was doing it like this, but it's not working.


I've created table using:
create table xml_orders(xml_col xml)
Then I inserted value to its doing:
INSERT
INTO
    xml_orders
VALUES
    (      XMLPARSE(DOCUMENT '
<orders>
  <singleOrder no="1" date="2015-01-22">
  </singleOrder>
</orders>
'PRESERVE WHITESPACE) )

But when I'm doing query like this:

SELECT XMLSERIALIZE(
         XMLQUERY('//singleOrder/@date' PASSING BY REF xml_col EMPTY ON
         EMPTY) AS VARCHAR(1000)
     )AS CustomerId
FROM xml_orders
I'm getting error:
Caused by: ERROR 2200W: XQuery serialization error: Attempted to serialize one 
or more top-level Attribute nodes.
        at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
        at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
        at org.apache.derby.iapi.types.XML.XMLSerialize(Unknown Source)
        at 
org.apache.derby.exe.ac23ffc05bx0150xf290x866cx000006bfe7900.e0(Unknown Source)
        at org.apache.derby.impl.services.reflect.DirectCall.invoke(Unknown 
Source)
        at 
org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(Unknown 
Source)
        at 
org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(Unknown
 Source)
        at 
org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRow(Unknown 
Source)
        ... 38 more
Thank you,
Greg

Reply via email to