Generate XML using DOM ( DocumentObjectBuilder )

Have a task to generate XMl from POJO objects
XML to be generated is complex
<element1>
     <ElementChild>
          <ChildElement1>
               <ChildElement>
               </ChildElement>
          </ChildElement1>
          <ChildElement2>
               <ChildElement>
               </ChildElement>
          </ChildElement2>
          <ChildElement3>
               <ChildElement>
               </ChildElement>
          </ChildElement3>
          <ChildElement4>
               <ChildElement>
               </ChildElement>
          </ChildElement4>
     </ElementChild>
</element1>
not able to do because the complex queries and requirement to populate
The same has been done with the help of appending nodes to document and appending childs but it has to be automated with the help of writing loops
any help appreciated
Thanks and Regards!!!
Ninjajay9982

Can u send me the code. You might have missed out something on reading that XML .

Similar Messages

  • Convertion of flat file to XML using DOM

    Hi!
    I need help for convert a flat file to XML using DOM and by taking the validation of a specified DTD. Can any body help me in this regard.
    Bye,
    lat

    first you have to decide how the flat file will map to xml. Will you use attributes or pcdata for your fields, or both? Will there be a hierarchy, or will it be mostly flat?
    Once decided, you'd probably just use a BufferedReader to read the lines one at a time, and generate Dom nodes as appropriate, and stick them in the tree.

  • Rounding of decimal values into XML using DOM

    I want to roundoff 10.456 to 10.4(while generating the xml) using DOM.
    Please let me know how to handle this?
    Thanks in advance

    read the java.lang.Math API
    there are rounding functions there
    and next time please just use a search engine

  • 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();
    }

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

  • Generating XML using oracle10g (plsql)

    Hi,
    I have to generate XML using plsql, please somebody help me in this.
    Query is as below.
    First I need to select few columns COL1,COL2 AND COL3 from table let say TEMP1 on the basis of PK_ID.
    this selected columns should be in XML document which I need to return as OUT parameter.
    Now on the basis of COL1 fetched in the above query from TEMP table
    I need to fetch all the columns COL4,COL5 AND COL6 from its child table let say TEMP2 on the basis of COL1.
    Please suggest.

    SQL> select  dbms_xmlgen.getxml('select * from emp where deptno = 10')
      2    from  dual
      3  /
    DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
      <EMPNO>7782</EMPNO>
      <ENAME>CLARK</ENAME>
      <JOB>MANAGER</JOB>
      <MGR>7839</MGR>
      <HIREDATE>09-JUN-81</HIREDATE>
      <SAL>2450</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
    <ROW>
      <EMPNO>7839</EMPNO>
      <ENAME>KING</ENAME>
      <JOB>PRESIDENT</JOB>
      <HIREDATE>17-NOV-81</HIREDATE>
      <SAL>5000</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    <ROW>
      <EMPNO>7934</EMPNO>
      <ENAME>MILLER</ENAME>
    DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
      <JOB>CLERK</JOB>
      <MGR>7782</MGR>
      <HIREDATE>23-JAN-82</HIREDATE>
      <SAL>1300</SAL>
      <DEPTNO>10</DEPTNO>
    </ROW>
    </ROWSET>
    SQL> SY.

  • How to append the declaration tags to generated xml using Xquery

    Hi,
      How to append the declaration tags to generated xml using Xquery.generated XML is like
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Here I want to append the <?xml version="1.0" encoding="ISO-8859-1"?> and the result xml should be
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Can anybody help to do this.
    Thanks
    Mani

    First assign this element to a temp variable
    <ROOT>
      <CHILD1></CHILD1>
      <CHILD2></CHILD2>
    </ROOT>
    Now in XQuery expression create a new variable
    <?xml version="1.0" encoding="ISO-8859-1"?>
    $temp

  • Generating XMLs using queries

    Hi All,
    We have a situation as in where we have to generate a XML out of Oracle UCM. I want to know is there any way where i can generate XML using the reaultset of some query.
    Any inputs will be useful..
    Thanks.

    Hi!
    In IdocScript, you can work with the resultset and generate XML as you want ....
    You could also make your own java component that would generate XML.
    Romain.

  • Generating XML Using JAVA

    How to generate XML usng java without using following.
    import org.apache.xerces.dom.DocumentImpl;
    import org.apache.xml.serialize.OutputFormat;
    import org.apache.xml.serialize.XMLSerializer;
    XML to be generated is as follows.
    <?xml version="1.0" encoding="UTF-8"?>
    <Modi xmlns:xsi="Modi/Modi1">
    <docConfig>
    <className>PO</className>
    <classDesc>Purchase</classDesc>
    <create>Y</create>
    </docConfig>
    <indexConfig>
    <index sequence="1">
    <shortName>PODATE</shortName>
    <displayName>PO Date</displayName>
    <type>date</type>
    <length>10</length>
    </index>
    </indexConfig>
    </upload>

    Two answers.
    If you want to not use any of the XML-oriented classes, you can use a PrintWriter. Just code:
    PrintWriter pw = new PrinteWriter(whatever);
    pw.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
    etc.If you want to use XML-oriented classes, but just not these 3 (can't imagine why), then use
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    instead of XMLSerializer and OutputFormat, and
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    instead of the DocumentImpl
    Dave Patterson

  • Generate XML using package xmlgen

    I have the following query:
    select employ_id, last_name, first_name, salary from employ;
    I need generate xml like this:
    <row>
    <employ>
    <employ_id last_name="Dennis" First_name="david">1</employ>
    <salary>6</salary>
    </employ>
    </row>
    How can I get it using xmlgen package? Thanks.
    null

    No, you will not be able to do that. The
    problem is that the columns of the db table
    are mapped to XML elements rather then
    attributes. Your best bet at achieving your
    goal is that after you get your xml document
    from the XSU, you transform it using XSLT.
    The Oracle Parser does include the xsl processor.
    visar
    ps.: Today, when using XSU's java API, you can directly get a DOM tree representation of the XML document, which then you can pass directly to the XSL processor and transform it; unfortunately, the PL/SQL API (i.e. xmlgen) doesn only return a string (i.e. lob) representation of the XML doc. So you have to use the PL/SQL Parser to parse it, get it in the DOM format, and only then can you transform it. The good news is that I was assured that in the future the XMLGEN will have a call to get the XML doc in DOM rep.

  • Parsing xml using DOM parser in java

    hi there!!!
    i don have much idea about parsing xml.. i have an xml file which consists of details regarding indentation and spacing standards of C lang.. i need to read the file using DOM parser in java n store each of the attributes n elements in some data structure in java..
    need help as soon as possible!!!

    DOM is the easiest way to parse XML document, google for JDOM example it is very easy to implement.
    you need to know what is attribute, what is text content and what is Value in XML then easily you can parse your document with dom (watch for space[text#] in your XML document when you parse it).
    you get root node then nodelist of childs for root then go further inside, it is easy believe me.

  • Remove element from xml using dom.

    i want to remove an element from an xml file using dom.
    i remove the element but the whole content of the file is also deleted.
    how can i rewrite the file.

    vij_ay wrote:
    subject :Remove element from xml,but if empty element in input file then output should be <tag></tag>, not like <tag.xml/>I assume you mean <tag/> but why do you want this? Any application that will not accept this valid XML construct is flawed and a bug report should be raised against it.

  • How do I  generate XML using internal variables in a procedure

    I know there is a way to generate XML inside a procedure by querying the database such as
    SELECT XMLELEMENT("Emp",
    XMLFOREST(e.employee_id, e.last_name, e.salary))
    "Emp Element"
    FROM employees e WHERE employee_id = 204;
    Emp Element
    <Emp>
    <EMPLOYEE_ID>204</EMPLOYEE_ID>
    <LAST_NAME>Baer</LAST_NAME>
    <SALARY>10000</SALARY>
    </Emp>
    What I have unsuccessfully been trying to do is to basically do the same thing except using internal variables like
    DECLARE
    l_keytype CONTACTINFO.KEYTYPE%TYPE;
    l_keyvalue CONTACTINFO.KEYVALUE%TYPE;
    l_pricetag CONTACTINFO.PRICATEG%TYPE;
    l_xmlout CLOB;
    BEGIN
    l_keytype := '1';
    l_keyvalue := '3333';
    l_pricetag := '10';
    SELECT XMLELEMENT("ParamSet", .........................this is line 13
    XMLFOREST(l_keytype as "keytype", l_keyvalue as "keyvalue", l_pricetag as "pricetag"))
    "ParamSet Element"
    INTO l_xmlout FROM DUAL;
    DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
    end;
    What I'd like it to generate is
    <ParamSet>
    <KEYTYPE>1 </KEYTYPE>
    <KEYVALUE>3333</KEYVALUE>
    <PRICETAG>100</PRICETAG>
    </ParamSet>
    But what I get is a compile error
    Error report:
    ORA-06550: line 13, column 19: (line 13 is SELECT XMLELEMENT("ParamSet", )
    PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got -
    ORA-06550: line 13, column 1:
    PL/SQL: SQL Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    Also, I've been told that one issue with XMLFOREST is that if the value is null it won't generate the XML for it. Not good. I will still need the XML even if it is empty. Please help.

    Darn, Marc beat me. Here was my answer showing an alternative for returning an XMLType, since that is what the query returns as he said.
    DECLARE
       l_keytype    VARCHAR2(5);
       l_keyvalue   VARCHAR2(5);
       l_pricetag   VARCHAR2(5);
       l_xmlout     CLOB;
       l_xmltype    XMLTYPE;
    BEGIN
       l_keytype := '1';
       l_keyvalue := '3333';
       l_pricetag := '10';
       SELECT XMLELEMENT("ParamSet",
                 XMLFOREST(l_keytype as "keytype",
                           l_keyvalue as "keyvalue",
                           l_pricetag as "pricetag")).getClobVal()
         INTO l_xmlout
         FROM DUAL;
       DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
       SELECT XMLELEMENT("ParamSet",
                 XMLFOREST(l_keytype as "keytype",
                           l_keyvalue as "keyvalue",
                           l_pricetag as "pricetag"))
         INTO l_xmltype
         FROM DUAL;
       DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmltype.getClobVal());
    end;Here is a link to Oracle's on-line documentation
    http://www.oracle.com/technetwork/indexes/documentation/index.html
    so that you can pick your version and search for XMLElement and XMLForest to see their difference as well as listening to us.

  • Need to retrieve all the node values of xml using DOM parser..pls help

    I want to fetch each node value in this xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <Main>
    <AAAAA>
    <ES>ESValue</ES>
    <EI>EIValue</EI>
    </AAAAA>
    <BBBBB>
    <SIP>
    <ST>STValue</ST>
    <TB>TBValue</TB>
    <PM>PMValue</PM>
    <VIP>
    <CARP>
    <AN1>AN1Value</AN1>
    <BN>BNValue</BN>
    </CARP>
    <DARP>
    <SA>
    <AN2>AN2Value</AN2>
    <CN>CNValue</CN>
    </SA>
    </DARP>
    </VIP>
    </SIP>
    </BBBBB>
    </Main>
    output should be the inner text values of diffrent nodes that contain some values..
    i.e
    output:
    ESValue
    EIValue
    STValue
    TBValue
    PMValue
    AN1Value
    BNValue
    AN2Value
    CNValue
    so that i can use thses node values and put it them in database...

    pls check the above xml file in proper redable order...I need to parse using DOM and fetch node values that are present...
    <?xml version="1.0" encoding="UTF-8"?>
    <Main>
        <AAAAA>
            <ES>ESValue</ES>
            <EI>EIValue</EI>
        </AAAAA>
        <BBBBB>
            <SIP>
                <ST>STValue</ST>
                <TB>TBValue</TB>
                <PM>PMValue</PM>
                <VIP>
                    <CARP>
                        <AN1>AN1Value</AN1>
                        <BN>BNValue</BN>
                    </CARP>
                    <DARP>
                        <SA>
                            <AN2>AN2Value</AN2>
                            <CN>CNValue</CN>
                        </SA>
                    </DARP>
                </VIP>
            </SIP>
        </BBBBB>
    </Main>

Maybe you are looking for

  • How to delete all messages in Alert Inbox

    Hi Guys, Recently I have done Alert configuration. After that I got around 400 messages(mails) in my inbox. I am able delete one by one, but it is very time consuming. Is there any way to delete all mails at once. Advanced thanks, gujjeti

  • After the 10.9.4 update, ssh no longer worked until I poked a firewall hole for sshd-keygen-wrapper

    I upgraded two of my Macs, a Mac Mini, A, and a MacBook Air, B, to OS X 10.9.4, using Software Update. After that, I could no longer ssh from A to B, but ssh from B to A worked fine. After some poking around for differences, I then noticed that in Ma

  • Losing Logic instrument presets between sessions

    PLEASE HELP! I can't find the answer to this anywhere. Why do the instruments I use in my logic 8 sessions reset themselves when i return to the same session? I am Saving my sessions and doing all I can to retain it but when i come back to the sessio

  • Jco.JCO$Exception when create a new adaptive model in NWDS

    HI friends: when I create a new adaptive model in NWDS, error occurs: Warning:Creating a connection with Metamodel language <zh_CN> failed. Continuing with language <zh> Fatal: com.sap.mw.jco.JCO$Exception: Missing R3NAME=... or ASHOST=... in connect

  • Unexpected get for VLSN: X already waiting for VLSN: X-1

    Hi all, This early morning the following exception has been thrown on our production environment (Solaris 10 + JRE 6u17 64 bits + JE 4.1.10) when performing a transaction commit. com.sleepycat.je.EnvironmentFailureException: (JE 4.1.10) Environment m