Combine 2 tables in XML

Table T1:
C1  C2  C3 
1   2   3  
10  20  30 
100 200 300 Table T2:
COL1 COL2
A    B   
AA   BB   Desired output:
<ROWSET>
     <T1>
          <C1>1</C1>
          <C2>2</C2>
          <C3>3</C3>
     </T1>
     <T1>
          <C1>10</C1>
          <C2>20</C2>
          <C3>30</C3>
     </T1>
     <T1>
          <C1>100</C1>
          <C2>200</C2>
          <C3>300</C3>
     </T1>
     <T2>
          <COL1>A</COL1>
          <COL2>B</COL2>
     </T2>
     <T2>
          <COL1>AA</COL1>
          <COL2>BB</COL2>
     </T2>
</ROWSET>Please, help. Thanks.
with t1 as
select '1' c1, '2' c2, '3' c3 from dual
union
select '10' , '20' , '30' from dual
union
select '100' , '200' , '300' from dual
, t2 as
select 'A' col1, 'B' col2 from dual
union
select 'AA' , 'BB' from dual
select ...

Here's one way:
SQL>  with t1 as
select '1' c1, '2' c2, '3' c3 from dual union all
select '10' , '20' , '30' from dual union all
select '100' , '200' , '300' from dual
, t2 as
select 'A' col1, 'B' col2 from dual union all
select 'AA' , 'BB' from dual
select xmlserialize(content sys_xmlagg(x) indent) x from (
select xmlelement("T1", sys_xmlgen(c1), sys_xmlgen(c2), sys_xmlgen(c3)) x from t1
  union all
select xmlelement("T2", sys_xmlgen(col1), sys_xmlgen(col2)) from t2
X                            
<?xml version="1.0"?>        
<ROWSET>                     
  <T1>                       
    <C1>1</C1>               
    <C2>2</C2>               
    <C3>3</C3>               
  </T1>                      
  <T1>                       
    <C1>10</C1>              
    <C2>20</C2>              
    <C3>30</C3>              
  </T1>                      
  <T1>                       
    <C1>100</C1>             
    <C2>200</C2>             
    <C3>300</C3>             
  </T1>                      
  <T2>                       
    <COL1>A</COL1>           
    <COL2>B</COL2>           
  </T2>                      
  <T2>                       
    <COL1>AA</COL1>          
    <COL2>BB</COL2>          
  </T2>                      
</ROWSET>                    
1 row selected.Note: xmlserialize is just for formatting the output and not neccessary in general.

Similar Messages

  • Data from table in xml Format and Inserting it into  Table

    Hi All
    I have table where xml data is stored in long format with xml tag know i have read the entire xml xoulmn which is xml tag and insert it into diffrent table can any suggest me the code
    Thanks & Regards

    I believe you are on the wrong forum. You want the XML DB forum.
    See:
    XML DB

  • How to write a procedure to load the data into a table using xml file as input to the procedure?

    Hi,
    Iam new to the xml,
    can u please anyone help me how to write procedure to load the data into a table using xml as input parameter to a procedure and xml file is as shown below which is input to me.
    <?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>.
    Regards,
    vikram.

    here is the your XML parse in 11g :
    select *
      from xmltable('//Entity' passing xmltype
    '<?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>
    ') columns
      "dcode" varchar2(4000) path '/Entity/dcode',
      "ddesc" varchar2(4000) path '/Entity/ddesc',
      "reauthflag" varchar2(4000) path '/Entity/reauthflag'
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    Using this parser you can create procedure as
    SQL> create or replace procedure myXMLParse(x clob) as
      2  begin
      3    insert into MyXmlTable
      4      select *
      5        from xmltable('//Entity' passing xmltype(x) columns "dcode"
      6                      varchar2(4000) path '/Entity/dcode',
      7                      "ddesc" varchar2(4000) path '/Entity/ddesc',
      8                      "reauthflag" varchar2(4000) path '/Entity/reauthflag');
      9    commit;
    10  end;
    11 
    12  /
    Procedure created
    SQL>
    SQL>
    SQL> exec myXMLParse('<?xml version="1.0"?><DiseaseCodes><Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity></DiseaseCodes>');
    PL/SQL procedure successfully completed
    SQL> select * from MYXMLTABLE;
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    SQL>
    Ramin Hashimzade

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_tab_converted_data
    EXCEPTIONS
      CONVERSION_FAILED          = 1
      OTHERS                     = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • Writing from internal table to xml format

    Hi,
    I searched all the forum and I have a question on writing the data from internal table in xml format to the file on app.server.
    Data: ITAB1   TYPE TABLE OF SPFLI,
             L_XML  TYPE REF TO CL_XML_DOCUMENT.
      SELECT * FROM SPFLI INTO TABLE ITAB1.
    CREATE THE XML OBJECT
      CREATE OBJECT L_XML.
    CONVERT THE DATA TO XML
      CALL METHOD L_XML->CREATE_WITH_DATA( DATAOBJECT = ITAB1[] ).
    after this how to move the XML data in the object to a file on app.server.
    Thanks

    p_ufile is the path of the application server
    p_output is the internal table with data to be moved to app serv.
    OPEN DATASET p_ufile FOR OUTPUT IN TEXT MODE.
    LOOP AT p_output INTO wa_file.
    TRANSFER wa_file TO p_ufile.
    CLEAR wa_file.
    ENDLOOP.
    CLOSE DATASET p_ufile.
    for XML I guees the path p_ufile ill be <b>sap/usr/tmp/file.xml</b>

  • Converting XML as table to XML as string

    All,
    I am successfully able to convert XML table from Internal Table. Now, I would like to convert this XML Table into XML string.
    Any help on this will be appreciated.
    Regards,
    Salil
    Moderator message: please search for available information/documentation before asking.
    Edited by: Thomas Zloch on Dec 7, 2010 11:57 AM

    Howdy,
    CONCATENATE LINES OF lt_table into l_string SEPARATED BY cl_abap_char_utilities=>cr_lf.
    This will create a string of the lines of the internal table with a carriage return after each line.
    Cheers
    Alex

  • Export Internal Table to XML in Background

    Hi
    I need to export a internal table into xml file in background using open dataset. The file is getting created but i am not able to open the file using IE/XML editor . When i open the file uisng wordpad i can see some charcters at the end of file which prevents it from opening in xml editor. if i delete the characters(box like) and save the file. i am able to open the file
    When i downalod the same internal table via frontend using ws_downlod it works pefectly. no junk charcters are appended in the end. and hence files opens perfectly
    below is the extract of program
    START-OF-SELECTION.
       PERFORM get_data.
       PERFORM create_xml.
    FORM get_data.
       REFRESH accesos.
       CLEAR accesos.
       MOVE: '45050' TO accesos-socio-numero,
                     'MOISES MORENO' TO accesos-socio-nombre,
                     '0' TO accesos-socio-reposicion.
       APPEND accesos.
    ENDFORM.
    i am using the following function modules
    CALL FUNCTION 'SDIXML_DATA_TO_DOM'
            EXPORTING
                 name         = 'ACCESOS'
                 dataobject   = accesos[]
            IMPORTING
                 data_as_dom  = l_dom
    CHANGING
                 document     = m_document
            EXCEPTIONS
                 illegal_name = 1
                 OTHERS       = 2.
           CHECK NOT l_dom IS INITIAL.
    w_rc = m_document->append_child( new_child = l_dom ).
    CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
    document      = m_document
    IMPORTING
    xml_as_string = w_string
    size          = w_size
    TABLES
    xml_as_table  = it_xml
    EXCEPTIONS
    no_document   = 1
    OTHERS        = 2.
    LOOP AT it_xml INTO xml_tab-d.
         APPEND xml_tab.
       ENDLOOP.
    The following syntax for open datset which does not work
      lv_physcial_file = '
    hdat03\test.xml'.
    OPEN DATASET lv_physcial_file IN BINARY MODE   FOR OUTPUT MESSAGE l_msg.
       LOOP AT xml_tab.
         TRANSFER xml_tab TO lv_physcial_file.
       ENDLOOP.
    The ws_download function works
    CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
                   BIN_FILESIZE = W_SIZE
                   FILENAME = GK_RUTA
                   FILETYPE = 'BIN'
    TABLES
                   DATA_TAB = XML_TAB
    EXCEPTIONS
                   OTHERS = 10.
    many thnaks

    Hi Chetan,
    Can you just try changing the syntax to the following, I not sure if that will help but just try and see.
    OPEN DATASET  lv_physcial_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    Regards
    Mohamed

  • Internal Table to XML

    Hallo Experts,
    I have retrived a Internal Table from FM.
    CALL FUNCTION 'SRTUTIL_CONVERT_XML_TO_TABLE'
        EXPORTING
          xdoc             = lv_xstring
    IMPORTING
    *   ERROR_TEXT       =
         data             = lt_xml
    I have manipulated the Tagnames in the Internal Table lt_xml.
    Now I want to change the internal table to xml.
    Is there any FM or a class. can anyone help me??
    Thanks
    Kind regards
    rana Waseem

    Hallo,
    Thanks for your Reply. I am trying to manipulate the xml attributes in print report. I have the data in xstring form. I have changed it to internal Table with following code.
    CALL FUNCTION 'SRTUTIL_CONVERT_XML_TO_TABLE'
        EXPORTING
          xdoc             = lv_xstring
    IMPORTING
    *   ERROR_TEXT       =
         data             = lt_xml
    After the change in the table lt_xml I am trying to have once again a xstring to give to the Print Report. I have tried it with class
    LOOP AT lt_xml INTO ls_xml.
        CALL METHOD cl_soap_xml_helper=>transform_to_xml
          EXPORTING
            tag_name          = ls_xml-tag_name
            data              = ls_xml-tag_value
            data_type         = ls_xml-tag_type
            ignore_init_value = 'X'
    *    ignore_exception  =
          CHANGING
            xml               = lv_xstring_two
    *  ENDLOOP.
    but when I try to check the XML become an error
    The XML cannot be showed, when Stylesheet XSL  is used Remove the error and try again.
    I cannot understand where is the error. Because the orignal xstring from system is shown correct. But when I create the new xstring give error .
    Thanks for your help
    kind regards
    waseem

  • Convert data from internal table to XML file.

    Hi All,
    I am selecting data from database into one internal table.
    Now I want to convert data from internal table to xml file format and save in to my desktop. Please suggest me how I can achieve my requirement.
    Kindly reply me ASAP.

    Use this FM. SAP_CONVERT_TO_XML_FORMAT
    Check this link too -
    Re: Data Export in XML format
    XML files from ABAP programs

  • Re:User group,info set and Query combination table

    Hi,
      I would like to know the combination table of User group,info set and Query.
    Can any body please respond to my question?
    Regards,
    Suresh Kumar.

    Hi,
    Check the tables starting with AQG*.
    Reward points if useful.
    Regards,
    Atish

  • Persist XML Data to Database Table - Generic XML Schema

    Hi,
    I would like to represent data in XML format and persist to any database tables.
    The ideal xml is like:
    <TABLE NAME="TABLE1">
    <TABLEDEF><COLUMN NAME="COLUMN1"/><COLUMN NAME="COLUMN2"/></TABLEDEF>
    <ROW><COLUMN VALUE="value1"/><COLUMN VALUE="value2"/></ROW>
    <ROW><COLUMN VALUE="value11"/><COLUMN VALUE="value22"/></ROW>
    </TABLE>     
    <TABLE NAME="TABLE2">
    </TABLE>     
    The XML could then be parsed, and saved to database with JDBC by manually composing the statement strings.
    To reduce the coding effort (xml parsing, JDBC connection, etc), are there any open source projects available to achieve the above purpose? The popular O/R mapping tools like Hibernate, Castor, etc, can't handle this scanario because they require the knowledge of the tables on the server side in order to create the mapping files in advance.
    Thanks for the help!

    Hi,
    I would like to represent data in XML format and persist to any database tables.
    The ideal xml is like:
    <TABLE NAME="TABLE1">
    <TABLEDEF><COLUMN NAME="COLUMN1"/><COLUMN NAME="COLUMN2"/></TABLEDEF>
    <ROW><COLUMN VALUE="value1"/><COLUMN VALUE="value2"/></ROW>
    <ROW><COLUMN VALUE="value11"/><COLUMN VALUE="value22"/></ROW>
    </TABLE>     
    <TABLE NAME="TABLE2">
    </TABLE>     
    The XML could then be parsed, and saved to database with JDBC by manually composing the statement strings.
    To reduce the coding effort (xml parsing, JDBC connection, etc), are there any open source projects available to achieve the above purpose? The popular O/R mapping tools like Hibernate, Castor, etc, can't handle this scanario because they require the knowledge of the tables on the server side in order to create the mapping files in advance.
    Thanks for the help!

  • Condition records and tax code combination table

    CAn I know the table where both condition record and tax code stored.

    Hi Jose,
    I think you have quoted the tax procedure table.  There i have not found the tax codes. 
    My requirement is both condition records and tax codes combination table.
    I want to see for which condition type which tax code has been assigned.

  • Dynamic Table with XML Schema

    Hi, I am new to livecycle and wondering if there is any sample for setting up the dynamic table with XML schema so I can access the data through workbench's xpath. thanks.

    Ivor,
    Take a look at the samples shipped with Designer. For 8.2.1 release take a look at
    C:\Program Files\Adobe\LiveCycle Designer ES\8.2\EN\Samples\Forms\Purchase Order\Schema\Schema\Purchase Order.xsd
    and the form samples.
    Otherwise, forward a request to [email protected] I would be happy to send you a sample XDP with a dynamic table and a schema.
    Steve

  • Spry Tables and Xml Data Sets viewed in IE7

    Has anyone ever run into a problem with Spry Tables and Xml
    Data Sets viewed in IE7? Work fine in IE6 and Firefox, but get the
    error "exception caught while loading feed.xml: [object Error]" in
    IE 7. Any ideas?
    Attached is the xml I'm using.
    Thanks

    I came looking for the answer to this question. I could not
    find an answer. Eventually I found it the answer that worked for
    me, a graphic designer with not much experience in xml.
    The following url provided an errata file in PDF format:
    www.peachpit.com/dwcs3cib
    which includes the following addendum to the incomplete
    instructions in the book i was using to learn about spry:
    "If Internet Explorer 7 is your primary browser, you'll nee
    to take some extra steps to view spry dynamic content locally.
    First, your site must be within the local server webroot; be sure
    your Lessons folder is stored within the Inetpub>wwwroot folder.
    Next, double-click the site name in the files panel to open the
    Site Definition dialogue. Click the Testing Server category; from
    the Access List choose Local/Network. Click Okay to close the Site
    Definition dialogue. Now, when you preview your page with Internet
    Explorer, your local Web server (localhost) serves the page as
    designed."
    Horray for me! Now i can move on from here and actually get
    some work done!

  • Save Table in XML Automatically

    Hello,
    I need your help...
    I want to get in a oracle db one table in xml format. I saw that we have a ORACLE XML DB package, where I can run "select" to obtain tables in xml. What I wan to do now, it is to save the result in a windows folder automatically, for example each hour. Do you know how can I do that? any idea?
    Best Regards.

    If you can, could you give an example of stored procedure to save file in the server?Yes, here's an example :
    1) Create a directory object
    create or replace directory test_dir as 'c:\oracle\test';2) The procedure
    CREATE OR REPLACE PROCEDURE getEmployees
    IS
      xmldoc          CLOB;
      xmlprolog       VARCHAR2(80);
    BEGIN
      -- builds the XML prolog using the database charset for the encoding
      SELECT '<?xml version="1.0" encoding="' || utl_i18n.map_charset(value) || '"?>'
      INTO xmlprolog
      FROM nls_database_parameters
      WHERE parameter = 'NLS_CHARACTERSET'
      -- generates the XML document
      SELECT XMLSerialize(DOCUMENT
               XMLElement("Employees",
                 XMLAgg(
                   XMLElement("Employee",
                     XMLAttributes(empno as "id")
                   , XMLForest(
                       ename as "name"
                     , job as "job"
                     , hiredate as "hireDate"
                   order by empno
      INTO xmldoc
      FROM scott.emp
      WHERE deptno = 10
      -- writes the document to a file in the directory TEST_DIR
      DBMS_XSLPROCESSOR.clob2file(xmlprolog || xmldoc, 'TEST_DIR', 'employees.xml');
    END;
    /When called, it'll create a file "employees.xml" containing :
    <?xml version="1.0" encoding="UTF-8"?>
    <Employees>
    <Employee id="7782">
      <name>CLARK</name>
      <job>MANAGER</job>
      <hireDate>1981-06-09</hireDate>
    </Employee>
    <Employee id="7839">
      <name>KING</name>
      <job>PRESIDENT</job>
      <hireDate>1981-11-17</hireDate>
    </Employee>
    <Employee id="7934">
      <name>MILLER</name>
      <job>CLERK</job>
      <hireDate>1982-01-23</hireDate>
    </Employee>
    </Employees>(formatted)

  • Insert data into oracle table from XML file

    I need to insert data into oracle table from XML file
    If anybody handled this type of scenario, Please let me know how to insert data into oracle table from XML file
    Thanks in advance

    The XML DB forum provides the best support for XML topics related to Oracle.
    Here's the FAQ on that forum:
    XML DB FAQ
    where there are plenty of examples of shredding XML into Oracle tables and such like. ;)

Maybe you are looking for