XMLFOREST vs XMLELEMENT vs ...?

TMiller Source

This is my first time writing XML and am tasked with outputting it like so:

<DATA_ROOT>
  <CREATEDBY header="Exported by">InvoicePro Storage Template 1.0</CREATEDBY>
  <TIMESTAMP header="Date">08.07.2016</TIMESTAMP>
  <BASICDATA header="Invoice" fieldnameheader="Field Name" datavalueheader="Value">
    <DATA_ITEM>
      <DBFIELD>comp_no</DBFIELD>
      <CAPTION>Company Number</CAPTION>
      <VALUE>COMP123</VALUE>
    </DATA_ITEM>
    <DATA_ITEM>
      <DBFIELD>comp_name</DBFIELD>
      <CAPTION>Company Name</CAPTION>
      <VALUE>Exmaple Company name</VALUE>
    </DATA_ITEM>
  <BASICDATA>
<DATAROOT>

(The above tags/data items change, this was an example that I was given)

So I started with this (just trying to display two sets of data_items), and it works, however I noticed that the BASICDATA header, filenameheader, and dataavalueheader stuff is not present:

XMLFOREST(
    XMLCONCAT(
            XMLELEMENT("CREATEDBY",XMLATTRIBUTES('Exported By' AS "header"), 'Magellan IT'),
            XMLELEMENT("TIMESTAMP",XMLATTRIBUTES('Date' AS "header"), TO_CHAR(SYSDATE,'MM.DD.YYYY')),
            XMLFOREST(
                XMLFOREST(
                    XMLFOREST(
                        'invoice_id' AS "DBFIELD",
                        'Invoice ID' AS "CAPTION",
                        r_markviewimport.invoice_id AS "VALUE"
                    ) AS "DATA_ITEM",
                    XMLFOREST(
                        'vendor_num' AS "DBFIELD",
                        'Vendor Num' AS "CAPTION",
                        r_markviewimport.vendor_num AS "VALUE"
                    ) AS "DATA_ITEM"
                ) AS "BASICDATA"
            )       
        ) AS "DATA_ROOT"
    )

In order to get it to show up I tried this which will display the basicdata header stuff, but once I add another XMLFOREST DATA_ITEM, it will not run:

XMLFOREST(
    XMLCONCAT(
            XMLELEMENT("CREATEDBY",XMLATTRIBUTES('Exported By' AS "header"), 'Magellan IT'),
            XMLELEMENT("TIMESTAMP",XMLATTRIBUTES('Date' AS "header"), TO_CHAR(SYSDATE,'MM.DD.YYYY')),
            XMLELEMENT("BASICDATA",XMLATTRIBUTES('Invoice' AS "header", 'Field Name' AS "fieldnameheader", 'Value' AS datavalueheader),
                XMLELEMENT("DATA_ITEM",
                    XMLFOREST(
                        'invoice_id' AS "DBFIELD",
                        'Invoice ID' AS "CAPTION",
                        r_markviewimport.invoice_id AS "VALUE"
                    ) 

                ) AS "BASICDATA"
            )        
        ) AS "DATA_ROOT"
    )

What am I missing?
As I said, I am brand new to XML and still don't fully understand the elements/forests/concatenates/etc.

sqlxmlplsql

Answers

comments powered by Disqus