7 Replies Latest reply on Oct 30, 2018 7:56 PM by Pavel_p

    Get a real Empty Page

    mpatzwahl

      Hello,

      mayby this is stupid question, so sorry ...

       

      I would like to generate a XML Sitemap for the Google Seachengine

       

      Something like ..

      "<?xml version="1.0" encoding="UTF-8"?>

      <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"

      <url><loc>http://xxx/ords/f?p=10000:0</loc><lastmod>2018-07-31</lastmod><changefreq>daily</changefreq></url>

       

      But when i try to delete all entries from a copy of a page Template (without removing #BODY# for a dynamic pl/sql region) i get errors like <HEAD> and </HEAD> are needed and so on.

      Is there are a easier way to generate a xml Page?

      Thanks

      Marco

        • 1. Re: Get a real Empty Page
          Pierre Yotti

          APEX need all That Html Tags, Why do you want to remove it? You can not generate xml Page? Your requirements are to clear

          • 2. Re: Get a real Empty Page
            fac586

            mpatzwahl wrote:

             

            mayby this is stupid question, so sorry ...

             

            I would like to generate a XML Sitemap for the Google Seachengine

             

            Something like ..

            "<?xml version="1.0" encoding="UTF-8"?>

            <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"

            <url><loc>http://xxx/ords/f?p=10000:0</loc><lastmod>2018-07-31</lastmod><changefreq>daily</changefreq></url>

             

            But when i try to delete all entries from a copy of a page Template (without removing #BODY# for a dynamic pl/sql region) i get errors like <HEAD> and </HEAD> are needed and so on.

            Is there are a easier way to generate a xml Page?

            You need to think outside the box for this one. Instead of a standard page, use an On-Demand application process or a page that only contains a classic report with the predefined XML template: How to create a custom xml-page?

            • 3. Re: Get a real Empty Page
              Pavel_p

              Hi Marco,

              I assume that you actually want to create a xml file rather than a html page. To generate a static file, create a blank page with a before header process like this:

              declare
                l_content varchar2(32767); --eventually clob
              begin
                  --get somehow the content
                  l_content := '<?xml version="1.0" encoding="UTF-8"?>
                              <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"
                              <url><loc>http://xxx/ords/f?p=10000:0</loc><lastmod>2018-07-31</lastmod><changefreq>daily</changefreq></url>';
              
                  htp.init;
                  owa_util.mime_header( 'text/xml', FALSE,'UTF-8' );
                  htp.p('Content-length: ' || length( l_content ));
                  htp.p('Content-Disposition: attachment; filename="sitemap.xml"' );
                  owa_util.http_header_close;
              
                  htp.p(l_content);
                  apex_application.stop_apex_engine;
              end;
              

              However to keep the sitemap.xml file synchronized with the real status seems to be cumbersome, so I believe we can generate the sitemap.xml dynamically from the application metadata (specifically APEX_APPLICATION_PAGES view) like this:

              declare
                l_site_xml xmltype;
                l_site_clob clob;
              begin
                  --generate the sitemap from app metadata
                  select xmlroot(
                  xmlelement("urlset", xmlattributes ('http://www.sitemaps.org/schemas/sitemap/0.9' as "xmlns"),
                  xmlagg(
                    xmlelement("url",
                    xmlelement("loc" , 'http://base_url/app_id.../f?p=' ||page_id) ,
                    xmlelement("lastmod" , to_char(last_updated_on,'yyyy-mm-dd')) ,
                    xmlelement("changefreq" , 'daily')
                    )
                    )), version '1.0" encoding="UTF-8', standalone yes) X
                    into l_site_xml
                    from apex_application_pages
                    where application_id = :app_id;
              
                  l_site_clob := l_site_xml.getclobval();
                  htp.init;
                  owa_util.mime_header( 'text/xml', FALSE,'UTF-8' );
                  htp.p('Content-length: ' || length( l_site_clob ));
                  htp.p('Content-Disposition: attachment; filename="sitemap.xml"' );
                  owa_util.http_header_close;
              
                  htp.p(l_site_clob); --if you expect large app (more than 32k chars in xml), convert to blob and serve it with wpg_docload.download_file
                  apex_application.stop_apex_engine;
              end;
              

              For my current little app it produces this output:

              <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
              <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
                <url>
                  <loc>http://base_url/app_id.../f?p=101</loc>
                  <lastmod>2018-10-27</lastmod>
                  <changefreq>daily</changefreq>
                </url>
                <url>
                  <loc>http://base_url/app_id.../f?p=1</loc>
                  <lastmod>2018-10-28</lastmod>
                  <changefreq>daily</changefreq>
                </url>
                <url>
                  <loc>http://base_url/app_id.../f?p=3</loc>
                  <lastmod>2018-10-28</lastmod>
                  <changefreq>daily</changefreq>
                </url>
                <url>
                  <loc>http://base_url/app_id.../f?p=2</loc>
                  <lastmod>2018-10-27</lastmod>
                  <changefreq>daily</changefreq>
                </url>
                <url>
                  <loc>http://base_url/app_id.../f?p=100</loc>
                  <lastmod>2018-10-28</lastmod>
                  <changefreq>daily</changefreq>
                </url>
              </urlset>
              

              If you expect larger application and your sitemap would eventually exceed 32767 characters, you might want to convert the l_site_clob variable to blob and serve it using wpg_docload.download_file ( Re: How to generate JSON file on demand from Apex 5.1 on 11.2 database ).

              Regards,

              Pavel

              1 person found this helpful
              • 4. Re: Get a real Empty Page
                fac586

                Pavel_p wrote:

                 

                I assume that you actually want to create a xml file rather than a html page. To generate a static file, create a blank page with a before header process

                Why create a page and a process? A page that isn't really a page is confusing. Cut straight to the chase and use an ODP.

                 

                Also note that xmlroot is deprecated. Use xmlserialize instead.

                • 5. Re: Get a real Empty Page
                  Pavel_p

                  Yes, to create an application process would be cleaner but on the other hand this "fake" page (reasonably named to avoid eventual confusion) or process should be probably publicly accessible and I think that to get the URL of a real page is simpler than the URL of application process.

                  I'm getting tired of all these deprecations and changed behaviour, thank you for pointing it out, I had no idea about it.

                  1 person found this helpful
                  • 6. Re: Get a real Empty Page
                    mpatzwahl

                    Pavel_p THANK YOU VERY MUCH.

                    If you ever come to Munich, i spend a beer for you :-)

                     

                    Kind regards

                    Marco

                    • 7. Re: Get a real Empty Page
                      Pavel_p

                      Marco, sorry, I don't drink beer. Um...just kidding.

                      Anyway, please, close the thread if your problem is solved.

                      1 person found this helpful