What I’m trying to do is create a stored procedure that will generate an xml that looks like the following.
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:georss="http://www.georss.org/georss" version="2.0">
<rowset>
<row>
<title>myTitle</title>
<description>myDescription</description>
<georss:point>myLat myLon</georss:point>
</row>
...
</rowset>
</rss>
Which I have the following to generate
SELECT DBMS_XMLGEN.getXML(q'!
SELECT trim(sitedesc) AS "title",
'<a href="../scripts/fmiinfo.asp?file_code=_BLDGLIST&sitecode='||trim(sitecode)||'&forceDB=">'||trim(siteabbrev)||'</a>' AS "description",
trim(latitude)|| ' ' ||trim(longitude) AS "georss:point"
FROM LS
WHERE sold <> 1
!') FROM dual;
Output looks like this
<ROW>
<title>Tipton Facilities</title>
<description><a href="../scripts/fmiinfo.asp?file_code=_BLDGLISTnull=USINTI01null=">TIP1</a></description>
<georss:point>40.286008 -86.058054</georss:point>
</ROW>
In the ‘description’ I want to have a link to another page, I understand xml has certain reserved characters like > < & % it looks like the output automatically converts the reserved characters into it’s entity reference accordingly.
The problem however is that the program thinks sitecode and forcedb in the url are variables, when they are not, and they get dropped from the results.
The url should be: <a href="../scripts/fmiinfo.asp?file_code=_BLDGLIST&sitecode=USINTI01&forceDB=">
But it’s <a href="../scripts/fmiinfo.asp?file_code=_BLDGLISTnull=USINTI01null=">
Will I need to type out the url with ctr() function to get the desired output?
SET SCAN OFF fixes my variable question.
Updating sample code per below comments.
SELECT XMLELEMENT("rss", XMLATTRIBUTES('http://www.georss.org/georss' AS "xmlns:georss"),
XMLELEMENT("channel",
XMLAGG(XMLELEMENT("item",
XMLFOREST(title AS "title",
description AS "description",
point AS "georss:point"))))).EXTRACT('/*')
FROM (SELECT trim(longitude) || ' ' || trim(latitude) AS point,
'../scripts/fmiinfo.asp?file_code=_BLDGLIST&sitecode='||trim(sitecode)||'&forceDB=">'||trim(siteabbrev)||'</a>' AS description,
trim(sitedesc) AS title
FROM ls
WHERE sold <>1
);
you’ve run this from sqlplus. sqlplus by default sees an ampersand as a substitution character. to disable this, run in sqlplus “set scan off”. GUIs will have an equivalent settting to stop checking for subsitution variables.
your rss would be much easier and neater if you used XMLX functions (XMLForest, XMLElement).
eg