Code Listing 3: Use XMLAgg to aggregate XML elements.


SELECT XMLElement("County",
       XMLAttributes(c.county_name AS "Name",
                     'http://www.w3.org/2001/XMLSchema-instance'
                        AS "xmlns:xsi",
                     'http://gennick.com/tourist.xsd'

                        AS "xsi:noNamespaceSchemaLocation"),
          XMLAgg(
             XMLElement("Attraction", 
                        XMLAttributes(government_owned AS GOV),
                XMLForest(a.attraction_name AS "Name", 
                          a.Location AS "Location", 

                          a.attraction_url AS "URL"))))
FROM county c INNER JOIN attraction a
     ON c.county_name = a.county_name
GROUP BY c.county_name;

XMLELEMENT("COUNTY",XMLATTRIBUTES(C.COUNTY_NAMEAS"NAME",'HTTP://WWW.
----------------------------------------------------------------------------------------------------------------------------

<County Name="Alger" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://gennick.com/tourist.xsd">
  <Attraction GOV="Y">
    <Name>Pictured Rocks</Name>
    <Location>Munising</Location>
    <URL>http://www.nps.gov/piro/</URL>
  </Attraction>
  <Attraction GOV="Y">
    <Name>Valley Spur</Name>

    <Location>Munising</Location>
    <URL>http://ValleySpur.com</URL>
  </Attraction>
</County>

...

<County Name="Marquette" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://gennick.com/tourist.xsd">
  <Attraction GOV="N">

    <Name>Da Yoopers Tourist Trap</Name>
    <Location>Ishpeming</Location>
    <URL>http://www.dayoopers.com/thetrap.html</URL>
  </Attraction>
  <Attraction GOV="N">
    <Name>Ski Hall of Fame</Name>
    <Location>Ishpeming</Location>
    <URL>http://skihall.com/www/</URL>
  </Attraction>
</County>



E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy