Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML to JSON

Mettemusens2Jan 3 2011 — edited Jan 4 2011
Hi there

I'm on an XE 10 (for the webservices) and have an 11.2 internal systems use.

I have a pl/sql procedure, which returns an XML. This is fine, but now a mobile app wants to access the XML in JSON format.

I just want to convert the xml to json on specific occations. I found this XML->JSON conversion site and have tested both versions of the XSLT - but they fail with various parse errors:

http://www.bramstein.com/projects/xsltjson/

This is the SQL I used for testing at the moment.

SELECT XMLtransform(xmltype('<test>Mette</test>'),
(SELECT xmltype (style_lob) FROM xml_stylesheet WHERE id = 3 and system = 'MOBIL')).getClobVal() x
from dual;

This is the definition of the TABLE:

CREATE TABLE "XML_STYLESHEET"
(
"ID" NUMBER,
"SYSTEM" VARCHAR2(10 BYTE),
"STYLESHEET" "MOBILER"."XMLTYPE",
"STYLE_LOB" CLOB
);

Since I dont know much about XSLTs can anyone help me get this XML->JSON to work.
I would prefer it to work on the XE (10g) - but 11.2 will also be OK for me.

regards
Mette

----------------------
Errors from the SQL statement: V1 of XSLT

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00602: Invalid child element 'search' of element 'stylesheet'.
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.


Errors from SQL statement: V2 of XSLT:

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00605: Invalid attribute 'as' in element 'param'.
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.

This does not fail - so the XSLT is a valid XML:

SELECT xmltype (style_lob) FROM xml_stylesheet WHERE id = 3 and system = 'MOBIL';

This does not fail - so the XML Data to be converted is a valid XML:

select xmltype('<test>Mette</test>') from dual;

Edited by: Mettemusens2 on 2011-01-03 05:08
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2011
Added on Jan 3 2011
8 comments
2,564 views