Generate XML with SAX (OutputFormat/XMLSerializer deprecated)

Hi,
I'm working on a project using an old code, written by don't-know-who, which generates XML code from data obtained at the moment, at run-time, and then returns it as a String.
Recently, my project included a new version (2.9) of the xercesImpl.jar library, and now classes OutputFormat and XMLSerializer have become deprecated.
I'd like to update the old code. Do you know how to modify my code in order to do exactly the same things with a "new" approach which is not deprecated?
I tried to search in the net and I found this FAQ <http://xerces.apache.org/xerces2-j/faq-general.html#faq-6>, but I didn't understand at all how to convert my code. :(
Here's a "semplified" version of my method:
public String generateDocument() {
    OutputFormat of = new OutputFormat("XML", "UTF-8", true);
    of.setIndent(1);
    of.setIndenting(true);
    StringWriter sw = new StringWriter();
    XMLSerializer xs = new XMLSerializer(sw, of);
    try {
        ContentHandler hd = xs.asContentHandler();
        hd.startDocument();
        AttributesImpl atts = new AttributesImpl();
        atts.addAttribute("", "", "id", "CDATA", "1");
        hd.startElement("", "", "addressBook", atts);
        atts.clear();
        hd.startElement("", "", "name", atts);
        String s = "John";
        hd.characters(s.toCharArray(), 0, s.length());
        hd.endElement("", "", "name");
        hd.startElement("", "", "surname", atts);
        s = "Smith";
        hd.characters(s.toCharArray(), 0, s.length());
        hd.endElement("", "", "surname");
        hd.endElement("", "", "addressBook");
        hd.endDocument();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    return sw.toString();
}This code returns a String with this content:
<addressBook id="1">
  <name>John</name>
  <surname>Smith</surname>
</addressBook>Thanks a lot.

This is easy. You have to somewhen learn the basics of the Java XML APIs, e.g. the DOM API. Or fight like a man through
http://java.sun.com/webservices/reference/tutorials/jaxp/html/dom.html
http://java.sun.com/webservices/reference/tutorials/jaxp/html/intro.html
http://java.sun.com/webservices/docs/1.6/tutorial/doc/index.html.

Similar Messages

  • EBS-R12 Generate XML (with data) from Embedded Data Definition

    Hi
    I'm new to running XMLP/BIP in EBS.
    I have found the extensive set of data definitions and templates in EBS and they work great out of the box.
    I, however, need to make template modifications.
    To this end, a correctly structured XML data template - containing all the data fields - is needed for loading into the template-builder in Word.
    If for example I take the embedded R12 data definition - XLAJELINESRPT.xml - for Posted Payable Invoices, and load it into the template builder, it provides the structure of the data template and not the structure of the output XML data.
    I have tried several ways to run the Data definition through XMLP using the concurrent manager attempting to intercept the generated XML (with data) but it either completes the process and uses the linked output template - producing the PDF - or other output - or if I remove the (output template altogether) it fails with an error.
    Maybe I'm missing an obvious step, but there has to be a way of taking the very comprehensive Data Definitions embedded in R12 EBS and using them in custom report templates.
    If I've totally missed the point, please give me the steps to follow.
    Many thaks in anticipation.
    Mike MacMurray

    HI Mike,
    You cannot load your Data Template into the MS Word Template Builder plugin, as it cannot be run to generate XML this way.
    You have two options to get the data from an XML Publisher Report run as a concurrent program in EBS.
    1) Using the XML Publisher Administrator responsibility, set an end date for both the Data Defintion and Template Definitions associated with the XLAJELINESRPT report.
    2) Leave the concurrent program, Data Defintions and Template Definitions exactly as they are and run the report. Once the report has completed, select the Concurrent Request, click "Diagnostics" then click "View XML". This will open the XML in a new browser window. You can then right click, View Source and then save this document locally.
    You can then load this XML into the MS Word Template Builder and start building your template.
    I hope this helps.
    Regards,
    Cj

  • Generate XML with tag names generated dynamically.

    Hi Mark,
    I want to generate xml in the following way using SQLXoperators.
    But only problem is when i use the operator, the tag name should be supplied before in hand as parameter.
    So it works well when the data for the tags are stored in seperate columns then its pretty simple.
    But lets say the whole hierarchy of the nodes is stored in one table with ID-->PARENTID relationship and the text is stored in a column called description.
    Now using CONNECT BY PRIOR i get the hierarchy and now based on the description value i have to generate the tags and then fill in the other details.
    This is just a summary of what i want. the below sample has much more than that and actual data comes from more than one table.
    But if i get the solution for what i asked before i think i can build the test of the thing.
    <?xml version="1.0" encoding="UTF-8"?>
    <SequenceData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SequenceData.xsd">
         <Header>
              <TemplateName>Template(XML)</TemplateName>
              <TemplateVersion>1.1</TemplateVersion>
              <CreatedUser>rsh2kor</CreatedUser>
              <CreatedDate>17-06-2005 12.12.22</CreatedDate>
         </Header>
         <List>
              <LoadPoints>
                   <LoadPoint description="Loadpoint1_in_list(level one)">
                        <SetPhase>
                             <SetPhaseVariables>
                                  <SetPhaseVariable>
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>100</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                             </SetPhaseVariables>
                             <MonitoredVariables>
                                  <MonitoredVariable>
                                       <ID>12344<ID>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Limit>10</Limit>
                                       <Tolerance>0.0</Tolerance>
                                       <Operator>&gt;</Operator>
                                       <AlertType>STOP</AlertType>
                                  </MonitoredVariable>
                             </MonitoredVariables>
                        </SetPhase>
                        <WaitPhase>
                             <WaitingTime>10</WaitingTime>
                             <MonitoredVariables>
                                  <MonitoredVariable>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Limit>10</Limit>
                                       <Tolerance>0.0</Tolerance>
                                       <Operator>&gt;</Operator>
                                       <AlertType>STOP</AlertType>
                                  </MonitoredVariable>
                             </MonitoredVariables>
                        </WaitPhase>
                        <MeasPhase>
                             <MeasPhaseVariables>
                                  <MeasPhaseVariable>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Result>0</Result>
                                  </MeasPhaseVariable>
                             </MeasPhaseVariables>
                        </MeasPhase>
                   </LoadPoint>
              </LoadPoints>
         </List>
         <Loop Iteration="5">
              <LoadPoints>
                   <LoadPoint description="Loadpoint2_in_Loop">
                        <SetPhase>
                             <SetPhaseVariables>
                                  <SetPhaseVariable LoopCount="1">
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>10</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                                  <SetPhaseVariable LoopCount="2">
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>20</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                                  <SetPhaseVariable LoopCount="3">
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>30</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                                  <SetPhaseVariable LoopCount="4">
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>40</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                                  <SetPhaseVariable LoopCount="5">
                                       <Name>pRail</Name>
                                       <Unit>bar</Unit>
                                       <Value>50</Value>
                                       <SettlingTime>0.0</SettlingTime>
                                  </SetPhaseVariable>
                             </SetPhaseVariables>
                             <MonitoredVariables>
                                  <MonitoredVariable>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Limit>10</Limit>
                                       <Tolerance>0.0</Tolerance>
                                       <Operator>&gt;</Operator>
                                       <AlertType>STOP</AlertType>
                                  </MonitoredVariable>
                             </MonitoredVariables>
                        </SetPhase>
                        <WaitPhase>
                             <WaitingTime>10</WaitingTime>
                             <MonitoredVariables>
                                  <MonitoredVariable>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Limit>10</Limit>
                                       <Tolerance>0.0</Tolerance>
                                       <Operator>&gt;</Operator>
                                       <AlertType>STOP</AlertType>
                                  </MonitoredVariable>
                             </MonitoredVariables>
                        </WaitPhase>
                        <MeasPhase>
                             <MeasPhaseVariables>
                                  <MeasPhaseVariable>
                                       <Name>MeasPoint</Name>
                                       <Unit>pascal</Unit>
                                       <Result>0</Result>
                                  </MeasPhaseVariable>
                             </MeasPhaseVariables>
                        </MeasPhase>
                   </LoadPoint>
              </LoadPoints>
              <List>
                   <LoadPoints>
                        <LoadPoint description="Loadpoint3_in_list(level two)">
                             <MonitoredVariables/>
                             <SetPhase>
                                  <SetPhaseVariables>
                                       <SetPhaseVariable>
                                            <Name>pRail</Name>
                                            <Unit>bar</Unit>
                                            <Value>100</Value>
                                            <SettlingTime>0.0</SettlingTime>
                                       </SetPhaseVariable>
                                  </SetPhaseVariables>
                                  <MonitoredVariables>
                                       <MonitoredVariable>
                                            <Name>MeasPoint</Name>
                                            <Unit>pascal</Unit>
                                            <Limit>10</Limit>
                                            <Tolerance>0.0</Tolerance>
                                            <Operator>&gt;</Operator>
                                            <AlertType>STOP</AlertType>
                                       </MonitoredVariable>
                                  </MonitoredVariables>
                             </SetPhase>
                             <WaitPhase>
                                  <WaitingTime>10</WaitingTime>
                                  <MonitoredVariables>
                                       <MonitoredVariable>
                                            <Name>MeasPoint</Name>
                                            <Unit>pascal</Unit>
                                            <Limit>10</Limit>
                                            <Tolerance>0.0</Tolerance>
                                            <Operator>&gt;</Operator>
                                            <AlertType>STOP</AlertType>
                                       </MonitoredVariable>
                                  </MonitoredVariables>
                             </WaitPhase>
                             <MeasPhase>
                                  <MeasPhaseVariables>
                                       <MeasPhaseVariable>
                                            <Name>MeasPoint</Name>
                                            <Unit>pascal</Unit>
                                            <Result>0</Result>
                                       </MeasPhaseVariable>
                                  </MeasPhaseVariables>
                             </MeasPhase>
                        </LoadPoint>
                   </LoadPoints>
              </List>
         </Loop>
    </SequenceData>
    Pls help as soon as possible.
    Thanks.

    I'm not Mark, but check out this article it may be helpful.
    http://www.oracle.com/technology/oramag/oracle/05-may/o35asktom.html
    In 10g there are other SQL statements besides connect by prior for parent child relationships.
    such as:
    CONNECT_BY_ROOT—returns the root of the hierarchy for the current row; this greatly simplifies our query. (See below for an example).
    CONNECT_BY_ISLEAF—is a flag to tell you if the current row has child rows.
    CONNECT_BY_ISCYCLE—is a flag to tell you if the current row is the beginning of an infinite loop in your hierarchy. For example, if A is the parent of B, B is the parent of C, and C is the parent of A, you would have an infinite loop. You can use this flag to see which row or rows are the beginning of an infinite loop in your data.
    NOCYCLE—lets the CONNECT BY query recognize that an infinite loop is occurring and stop without error (instead of returning a CONNECT BY loop error).

  • Generating XML with attributes using XSU

    Oracle document claims if the sql is:
    select empno as @empno from employee
    Using XSU to generate XML will produce and XML document with EMPNO as an attribute instead of element name. But this does not seem to work. There is an exception:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character '&' is not allowed in an XML tag name.</ERROR
    Is there anything wrong or is there a work around

    Oracle document claims if the sql is:
    select empno as @empno from employee
    Using XSU to generate XML will produce and XML document with EMPNO as an attribute instead of element name. But this does not seem to work. There is an exception:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: Character '&' is not allowed in an XML tag name.</ERROR
    Is there anything wrong or is there a work around

  • Can I parse non-wellformed XML with SAX at all?

    Hi all,
    i was wondering whether its possible at all to parse XML that is not well formed with SAX.
    e.g. A HTML file that doesnt close tags and stuff like that.
    I tried implementing the fatal() method of the Handler in a a way that it consumes the exception but does not rethrow it.
    Also I tried setting the validation property to false. Both with no success.
    Any help would be appriciated.
    thx
    philipp

    Your experiments tell you the answer.
    If you have HTML tag soup, why not just run it through JTidy or HTMLTidy to make it into well-formed XHTML?

  • How to Parse XML with SAX and Retrieving the Information?

    Hiya!
    I have written this code in one of my classes:
    /**Parse XML File**/
              SAXParserFactory factory = SAXParserFactory.newInstance();
              GameContentHandler gameCH = new GameContentHandler();
              try
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse(recentFiles[0], gameCH);
              catch(javax.xml.parsers.ParserConfigurationException e)
                   e.printStackTrace();
              catch(java.io.IOException e)
                   e.printStackTrace();
              catch(org.xml.sax.SAXException e)
                   e.printStackTrace();
              /**Parse XML File**/
              games = gameCH.getGames();And here is the content handler:
    import java.util.ArrayList;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    class GameContentHandler extends DefaultHandler
         private ArrayList<Game> games = new ArrayList<Game>();
         public void startDocument()
              System.out.println("Start document.");
         public void endDocument()
              System.out.println("End document.");
         public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
         public void characters(char[] ch, int start, int length) throws SAXException
              /**for (int i = start; i < start+length; i++)
                   System.out.print(ch);
         public ArrayList<Game> getGames()
              return games;
    }And here is the xml i am trying to parse:<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <Database>
         <Name></Name>
         <Description></Description>
         <CurrentGameID></CurrentGameID>
         <Game>
              <gameID></gameID>
              <name></name>
              <publisher></publisher>
              <platform></platform>
              <type></type>
              <subtype></subtype>
              <genre></genre>
              <serial></serial>
              <prodReg></prodReg>
              <expantionFor></expantionFor>
              <relYear></relYear>
              <expantion></expantion>
              <picPath></picPath>
              <notes></notes>
              <discType></discType>
              <owner></owner>
              <location></location>
              <borrower></borrower>
              <numDiscs></numDiscs>
              <discSize></discSize>
              <locFrom></locFrom>
              <locTo></locTo>
              <onLoan></onLoan>
              <borrowed></borrowed>
              <manual></manual>
              <update></update>
              <mods></mods>
              <guide></guide>
              <walkthrough></walkthrough>
              <cheats></cheats>
              <savegame></savegame>
              <completed></completed>
         </Game>
    </Database>I have been trying for ages and just can't get the content handler class to extract a gameID and instantiate a Game to add to my ArrayList! How do I extract the information from my file?
    I have tried so many things in the startElement() method that I can't actually remember what I've tried and what I haven't! If you need to know, the Game class instantiates with asnew Game(int gameID)and the rest of the variables are public.
    Please help someone...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    OK, how's this?
    public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
              current = "";
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
              try
                   if(qualifiedName.equals("Game") || qualifiedName.equals("Database"))
                        {return;}
                   else if(qualifiedName.equals("gameID"))
                        {games.add(new Game(Integer.parseInt(current)));}
                   else if(qualifiedName.equals("name"))
                        {games.get(games.size()-1).name = current;}
                   else if(qualifiedName.equals("publisher"))
                        {games.get(games.size()-1).publisher = current;}
                   etc...
                   else
                        {System.out.println("ERROR - Qualified Name found in xml that does not exist as databse field: " + qualifiedName);}
              catch (Exception e) {} //Ignore
         public void characters(char[] ch, int start, int length) throws SAXException
              current += new String(ch, start, length);
         }

  • Generate XML with answer values

    Hi Forum,
    I wnat to know if there is any function or method to generate a xml, a string, with the answer values. I want to generate this string to attach this survey with the all fields completed in an activity.
    Regards and thanks in advance,
    Mon

    Hi,
    you can use one of the following Classes for XML conversion.
    CL_PROXY_XML
    CL_CRM_XML_PROVIDER
    CL_CXF_XML_TOOLS
    Also if none of the above is useful, you can search one in SE24 with XML.
    There are lots and one will be definitely useful.
    Please reward with points in case helpful.
    Sharif.

  • Parse XML with SAX

    Hi all, I have the folow xml file:
    <n>
    <q>
    <r></r>
    <r></r>
    </q>
    </n>
    How can I make, that automaticli show me the elements of a tree?
    for Example:
    n includes r,r,q
    q includes r,r
    r includes r
    r includes r
    That I can show the Elements of all Trees?
    Thanks verry much.

    Read this tutorial:
    http://java.sun.com/webservices/docs/1.2/tutorial/doc/index.html
    It has some examples like that. If I knew what you wanted when you said "show" I could be more specific.

  • Generate XML with multiple parent nodes

    I have the following test data
    CREATE TABLE #TEST1 (
    HS VARCHAR(20),
    HN VARCHAR(20),
    NC FLOAT
    INSERT INTO #TEST1
    VALUES ('COMPLETE','ABC123',1234.56789),
    ('REJECTED','ABC124',1234.56789),
    ('PLANNED','ABC125',1234.56789),
    ('COMPLETE','ABC126',1234.56789),
    ('COMPLETE','ABC127',1234.56789),
    ('REJECTED','ABC128',1234.56789),
    ('COMPLETE','ABC129',1234.56789),
    ('PLANNED','ABC130',1234.56789),
    ('COMPLETE','ABC131',1234.56789),
    ('COMPLETE','ABC132',1234.56789),
    ('REJECTED','ABC133',1234.56789),
    ('COMPLETE','ABC134',1234.56789),
    ('PLANNED','ABC135',1234.56789),
    ('COMPLETE','ABC136',1234.56789),
    ('REJECTED','ABC137',1234.56789),
    ('COMPLETE','ABC138',1234.56789),
    ('COMPLETE','ABC139',1234.56789),
    ('PLANNED','ABC140',1234.56789)
    SELECT ( SELECT *
    FROM #TEST1 T
    FOR XML PATH('STATUS'), TYPE
    FOR XML PATH('Document'), ROOT('kml')
    DROP TABLE #TEST1
    Which produces the following results.
    <kml>
    <Document>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC123</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>REJECTED</HS>
    <HN>ABC124</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>PLANNED</HS>
    <HN>ABC125</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC126</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC127</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>REJECTED</HS>
    <HN>ABC128</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC129</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>PLANNED</HS>
    <HN>ABC130</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC131</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC132</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>REJECTED</HS>
    <HN>ABC133</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC134</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>PLANNED</HS>
    <HN>ABC135</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC136</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>REJECTED</HS>
    <HN>ABC137</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC138</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>COMPLETE</HS>
    <HN>ABC139</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    <STATUS>
    <HS>PLANNED</HS>
    <HN>ABC140</HN>
    <NC>1.234567890000000e+003</NC>
    </STATUS>
    </Document>
    </kml>
    What I really want to produce is this
    <kml>
    <Document>
    <STATUS>
    <HS>
    COMPLETE
    <Data>
    <HN>ABC123</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC126</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC127</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC129</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC131</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC132</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC134</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC136</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC138</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC139</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    </HS>
    </STATUS>
    <STATUS>
    <HS>
    REJECTED
    <Data>
    <HN>ABC124</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC128</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC133</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC137</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    </HS>
    </STATUS>
    <STATUS>
    <HS>
    PLANNED
    <Data>
    <HN>ABC125</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC130</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC135</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    <Data>
    <HN>ABC140</HN>
    <NC>1.234567890000000e+003</NC>
    </Data>
    </HS>
    </STATUS>
    </Document>
    </kml>
    Is it possible to group header and then group data under those headers using one SQL statement?
    Thanks in advance
    Q

    E.g.
    DECLARE @TEST1 TABLE
    HS VARCHAR(20) ,
    HN VARCHAR(20) ,
    NC FLOAT
    INSERT INTO @TEST1
    VALUES ( 'COMPLETE', 'ABC123', 1234.56789 ),
    ( 'REJECTED', 'ABC124', 1234.56789 ),
    ( 'PLANNED', 'ABC125', 1234.56789 ),
    ( 'COMPLETE', 'ABC126', 1234.56789 ),
    ( 'COMPLETE', 'ABC127', 1234.56789 ),
    ( 'REJECTED', 'ABC128', 1234.56789 ),
    ( 'COMPLETE', 'ABC129', 1234.56789 ),
    ( 'PLANNED', 'ABC130', 1234.56789 ),
    ( 'COMPLETE', 'ABC131', 1234.56789 ),
    ( 'COMPLETE', 'ABC132', 1234.56789 ),
    ( 'REJECTED', 'ABC133', 1234.56789 ),
    ( 'COMPLETE', 'ABC134', 1234.56789 ),
    ( 'PLANNED', 'ABC135', 1234.56789 ),
    ( 'COMPLETE', 'ABC136', 1234.56789 ),
    ( 'REJECTED', 'ABC137', 1234.56789 ),
    ( 'COMPLETE', 'ABC138', 1234.56789 ),
    ( 'COMPLETE', 'ABC139', 1234.56789 ),
    ( 'PLANNED', 'ABC140', 1234.56789 )
    SELECT O.HS ,
    ( SELECT I.HN ,
    I.NC
    FROM @TEST1 I
    WHERE I.HS = O.HS
    FOR XML PATH('') ,ROOT('Data'), TYPE
    ) AS HS
    FROM @TEST1 O
    GROUP BY O.HS
    FOR XML PATH('Document') , ROOT('kml');
    Caveat: You're using mixed element name casing.

  • Re: extract part  of xml with SAX

    alternatively do a XLST to extract the required node?

    would that be possible if i'm using the xerces sax2 parser to extract data?

  • Problem with generating xml and nested cursor (ora-600)

    I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
    When I execute the following command, I get a ORA-600 error:
    select dbms_xmlquery.getxml('select mst_id
    , mst_source
    , cursor(select per.*
    , cursor(select ftm_fdf_number
    , ftm_value
    from t_feature_master
    where ftm_mstr_id = pers_master_id ) as features
    from t_person per
    where pers_master_id = mst_id ) as persons
    from f_master
    where mst_id = 3059435')
    from dual;
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
    </ERROR>
    The problem is the second cursor (t_feature_master).
    I want to generate this:
    <master>
    <..>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    <persons>
    <..>
    <features>
    <..>
    </features>
    </persons>
    </master>
    If i execute the select-statement in sql-plus, then I get the next result.
    MST_ID MST_SOURCE PERSONS
    3059435 GG CURSOR STATEMENT : 3
    CURSOR STATEMENT : 3
    PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
    3059435 W. Name
    CURSOR STATEMENT : 15
    FTM_FDF_NUMBER FTM_VALUE
    1 [email protected]
    10 ....
    I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
    Is this a bug and do somebody know a workaround?

    Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.

  • Generate XML using Java

    Hi all,
    How can I genrate a XML document using Java? What are the imports that I have to use? Also please tell me about JAXP and in what way it can be used to generate an XML
    Please Help me with examples..
    Thanks in advance

    You can generate xml with dom like this
    try {
         DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
         Document document = docBuilder.newDocument();
         Element element = document.createElement("<your_tag_name>"); // creares tag
         element.setAttribute("key", "value"); // adds an attribute to your tag
         Text text = document.createTextNode("some text"); // creates "some text node"
         element.appendChild(text); // adds text to our tag for ex. <your_tag_name>some text</your_tag_name>
         CDATASection cdata = document.createCDATASection("cdata text");
         element.appendChild(cdata); // appends it to element
         document.appendChild(element); // if you want to add this element *** root element
         // or
         root.appendChild(element); // where  root is another Element object
    } catch (ParserConfigurationException e) {
         e.printStackTrace();
    }

  • Generating XML content with SAX including schema reference

    Hi all, XML newbie question here.
    I'm trying to generate an XML document from a certain file format using SAX, but I can't figure out how to get the generated XML document to include a schema reference.
    Here's the code, it's taken from posts on this forum, so it should be familiar:
    StreamResult streamResult = new StreamResult(out);
            SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try {
                TransformerHandler hd = tf.newTransformerHandler();
                Transformer serializer = hd.getTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                hd.setResult(streamResult);
                hd.startDocument();
                AttributesImpl atts = new AttributesImpl();
                hd.startElement("http://maul.ddm.apm.bpm.eds.com", "DTR_XML", "DTR_XML", atts);
                hd.endElement("http://maul.ddm.apm.bpm.eds.com", "DTR_XML", "DTR_XML");
                hd.endDocument();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (TransformerConfigurationException e) {
                e.printStackTrace();
            }Here's the output I get:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <DTR_XML/>
    And I'm looking for output like this (I think - basically I have this dtr_xml.xsd located at the root web directory on http://maul.ddm.apm.bpm.eds.com and I want the generated XML file to reference that schema for validation when parsing):
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <DTR_XML xmlns="http://maul.ddm.apm.bpm.eds.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd"/>

    Yes, you've led me along the right track with the attributes stuff. Here's what I've got right now...
    StreamResult streamResult = new StreamResult(out);
            SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try {
                TransformerHandler hd = tf.newTransformerHandler();
                Transformer serializer = hd.getTransformer();
                serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
                serializer.setOutputProperty(OutputKeys.INDENT, "yes");
                hd.setResult(streamResult);
                hd.startDocument();
                AttributesImpl atts = new AttributesImpl();
                atts.addAttribute("", "xmlns", "xmlns", "CDATA", "http://maul.ddm.apm.bpm.eds.com");
                atts.addAttribute("", "xsi", "xmlns:xsi", "CDATA", "http://www.w3.org/2001/XMLSchema-instance");
                atts.addAttribute("", "schemaLocation", "xsi:schemaLocation", "CDATA", "http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd");
                hd.startElement("", "DTR_XML", "DTR_XML", atts);
                hd.endElement("", "DTR_XML", "DTR_XML");
                hd.endDocument();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (TransformerConfigurationException e) {
                e.printStackTrace();
            }This produces the output I wanted earlier...
    As for the org.xml.sax.helpers.NamespaceSupport, I can't seem to find any documentation on using it anywhere, and the javadoc is cryptic to me. Maybe it's used internally in SAX for tracking namespaces or something like that.
    Another interesting thing to me is that if I use the code you gave:
    atts.addAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation",
         "xsi:schemaLocation", "CDATA", "http://maul.ddm.apm.bpm.eds.com dtr_xml.xsd");I don't see "http://www.w3.org/2001/XMLSchema-instance" anywhere in the output. Is SAX ignoring the namespace uri argument? It appears so. The javadoc states that the uri argument is "The Namespace URI, or the empty string if none is available or Namespace processing is not being performed." It would appear that Namespace processing is not being done... but I don't know how to turn it on.

  • Easiest and/or best methods for generating XML output (not with a report)

    Hi, several of our EBS customers (11.5.10) are converting their PDF reports to use XML/BI publisher to produce output. The data stream comes from a report that generates the XML output, and then the XML template is applied. This works great ... no problems, etc. From what I have read, however, Oracle intends to treat the traditional Forms and Reports Developers as legacy tools (although still supporting them, of course).
    My question is if I wanted to ditch using Reports to generate XML output, what, in your opinion or in your current usage, is the easiest way of getting this data? In Reports, the data modeler is excellent in providing a method to write your queries, split them into different repeating groups, write formula and summary columns, link multiple queries, etc, etc. If one were to become Reports Developer free, what comparable tools are available to take its place? I would expect this tool to handle a mix of GUI and coding like the Reports data modeler. Please note that I'm not looking for an EBS-specific solution -- say for a custom application using regular Oracle 10g DB and iAS, with BI Publisher for reporting.
    Thanks for your feedback,
    Ryan

    What I'm looking for is to not use Oracle Reports to generate the XML data output since Oracle's statement of direction is pushing BI Publisher rather than Oracle Reports as the preferred tool for reporting. That said, the data modeler in Reports provides a very flexible tool to construct and link multiple queries and to manipulate the queries into several levels of a master/detail relationship. Further, the mix of GUI and coding makes setting up the data model a lot more efficient. What I'm looking for (and I don't know if anything exists) is something comparable that can be used to generate XML output from the DB -- the idea being that I wouldn't use legacy tools, like Reports, for this task. I hope that is clearer.
    Really, another way of answering my question is, aside from Reports and the APIs mentioned so far, what are my fellow developers using, if anything, to extract XML data in a way that handles the features i list above?

  • How to generate xml-file for SAP Fiori (UI add-on) with Solution Manager 7.0.1?

    Hello Guru,
    could you please help with my issue with Fiori Installation.
    We want to install SAP Fiori Front-End (GW+UI) on the Sandbox system with SAP Netweaver 7.3.1. (SP14)
    Gateway component (SAP GW CORE 200 SP10) was installed without any problems.
    But I need to install UI-add-on (NW UI Extensions v1.0) and when I try to install it via SAINT, transaction said me that I need to generate xml-file for it (as in General notes for UI add-on mentioned).
    But I have Solution Manager 7.0.1 and in MOPZ for this version I do not have option  "install Add-on" as it written in Guide for ui add-on installation.
    Could you please help me with advice how to generate xml-file for UI add-on installation on SolMan v.7.0.1?
    If where is no way, but only to upgrade Solution Manager, maybe somebody could give me xml-file for your system (for NW 731) and I will change it to my needs, I will be very grateful!
    Thanks in advance for any help!!!
    Bets regards,
    Natalia.

    Hello Guru,
    could you please help with my issue with Fiori Installation.
    We want to install SAP Fiori Front-End (GW+UI) on the Sandbox system with SAP Netweaver 7.3.1. (SP14)
    Gateway component (SAP GW CORE 200 SP10) was installed without any problems.
    But I need to install UI-add-on (NW UI Extensions v1.0) and when I try to install it via SAINT, transaction said me that I need to generate xml-file for it (as in General notes for UI add-on mentioned).
    But I have Solution Manager 7.0.1 and in MOPZ for this version I do not have option  "install Add-on" as it written in Guide for ui add-on installation.
    Could you please help me with advice how to generate xml-file for UI add-on installation on SolMan v.7.0.1?
    If where is no way, but only to upgrade Solution Manager, maybe somebody could give me xml-file for your system (for NW 731) and I will change it to my needs, I will be very grateful!
    Thanks in advance for any help!!!
    Bets regards,
    Natalia.

Maybe you are looking for

  • I want to see multiple pins on Maps app.  Is this possible?

    Basically, I would love to be able to click on Maps app on my iphone, and depending on where I am, see the map and any bookmarks I have saved in my phone.  For example, if I wanted to pin all my contacts on a map and see pins on where they are, but A

  • Where does it go when you click on the Calendar icon beside the date field?

    Hi, Does anybody know what page or region does it go when you click on the Calendar icon beside a date field? I need to know how it generates the list of values for year. Need your help. ASAP. If you need to know more about my inquiry please email me

  • Nowuptodate won't launch in mavericks

    Now Up To Date will no longer work in mavericks.  It is my primary calendar program.  Won't uninstall, but I did a reinstall and still won't work

  • Is MasterSuite Cs5.5 compatible with Most recent imac running on OS X Lion V10.7

    Hi all, I really need some help. I just bought the mastersuite cs5.5 collection and I cannot even instal it onto my brand new iMac. My mac is the latest model on the market and when I insert the software CD nothing happens. Is there something missing

  • HttpService Sandbox Violation

    Hi: In FB 3 have an HttpService request that works fine running from within Flex Builder environment. When I deploy the application to the same server to which I do the http request it also works on the client. When I deploy to a tomcat localhost and