Reputation: 11
Select xmlcast('<case_id>123</case_id><checknumb>2345</checknumb>' as XML)
This query returns
<case_id;gt;123</case_id
<checknumb>2345</checknumb
How to get
<case_id>123</case_id<checknumb>2345</checknumb>
Why its coming like this when casting into xml.
Upvotes: 0
Views: 740
Reputation: 12314
If you need to produce an XML sequence
, then you should use XMLCONCAT scalar function, and not try to cast a string constant to the XML type.
VALUES XMLCONCAT(XMLELEMENT(NAME "case_id", 123), XMLELEMENT(NAME "checknumb", 2345));
If you need to produce an XML document
, then you should use the following:
VALUES XMLELEMENT(NAME "doc", XMLCONCAT(XMLELEMENT(NAME "case_id", 123), XMLELEMENT(NAME "checknumb", 2345)));
Upvotes: 0
Reputation: 18980
Your code is trying to cast a string literal '<case_id>123</case_id><checknumb>2345</checknumb>'
as an XML string, not an XML document. XML strings cannot contain angle brackets inside them, because these symbols have special meaning for XML parsers, so the angle brackets are converted to entities.
If what you really want is to convert your literal '<case_id>123</case_id><checknumb>2345</checknumb>'
to an XML document, you need to make it a valid XML document first (by adding the root element) and then use XMLPARSE(DOCUMENT '<root><case_id>123</case_id><checknumb>2345</checknumb></root>')
instead.
Upvotes: 1