You can add the returns with a little shell script, like this:
#!/bin/sh
# Usage: ./addreturns.sh foobar.xml.
file=$1
cat $file | perl -pe 's|(<\/.*?>)|\1\n|g' | perl -pe 's|><|>\n<|g' > /tmp/newlines.xml; mv /tmp/newlines.xml $file
質問
I have the below query that returns everything in one line of the xml, is there a way to have the outpup in readable format? Like the sample below.
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(s.sitedesc) AS title,
'Employee Count: ' || s.sitefte || '<br /> Bldg Gross SF: ' || s.bldgarea || '<br />' || CASE WHEN s.leasestat = '0' THEN 'Owned' WHEN s.leasestat = '1' THEN 'Leased, end date: ' || trim(l.edate) END || '<br /><a href="../scripts/fmiinfo.asp?file_code=_BLDGLIST&sitecode='||trim(s.sitecode)||'&forceDB=">'||'More Details'||'</a> <br />' AS description,
trim(s.latitude) || ' ' || trim(s.longitude) AS point
FROM ls s
LEFT OUTER JOIN c0 l ON l.sitecode = s.sitecode
WHERE s.sold <> 1
AND s.longitude != ' '
)
;
returns
<rss xmlns:georss="http://www.georss.org/georss"><channel><item><title>TITLE</title><description>DESCRIPTION<description><georss:point>LAT LON</georss:point></item> ... </channel></rss>
But to make it easier to read would like the output closer to this:
<rss xmlns:georss="http://www.georss.org/georss">
<channel>
<item>
<title>TITLE</title>
<description>DESCRIPTION</description>
<georss:point>LAT LON</georss:point>
</item>
...
</channel>
</rss>
解決
You can add the returns with a little shell script, like this:
#!/bin/sh
# Usage: ./addreturns.sh foobar.xml.
file=$1
cat $file | perl -pe 's|(<\/.*?>)|\1\n|g' | perl -pe 's|><|>\n<|g' > /tmp/newlines.xml; mv /tmp/newlines.xml $file