Saving business objects into xml file

I have the following XML file parsed into a DOM tree, with 2 different types of nodes "TestCase" and
"RealCase". Then I mapped each type to a different type of business object, TestCaseObj and RealCaseObj.
Now, there may be addition of new objects, or modifications to the data stored in the business objects
by my application. Eventually when I save the business objects back into the XML file, how should I go
about doing that?
<ROOT>
<TestCase TestID="T1">
     <Element1>Data1</Element1>
     <Element2>Data2</Element2>
</TestCase>
<TestCase TestID="T2">
     <Element1>Data1</Element1>
     <Element2>Data2</Element2>
</TestCase>
<RealCase ID="R1">
     <Element1>Data1</Element1>
     <Element2>Data2</Element2>
     <Element3>Data3</Element3>
</RealCase>
<RealCase ID="R2">
     <Element1>Data1</Element1>
     <Element2>Data2</Element2>
     <Element3>Data3</Element3>
</RealCase>
</ROOT>

The DocumentBuilder class does not allow you to parse a portion of the xmlfile. Therefore, it will not be possible to read "TestCase" into the DOM without bringing in "RealCase" nodes as well. As such, these codes will parse the entire xml file into DOM:
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.parse( xmlFile );
However, your problem can be solved by reading only "TestCase" nodes in DOM, as follows:
NodeList elementNodeList =
elementNode.getElementsByTagName("TestCase");
Your codes will then change the data in the elementNodeList, without affecting "RealCase" although it is loaded into DOM. You can be sure that elementNodeList contains only "TestCase" nodes.
Once you have made your changes, save the DOM back to the XML file, using the serializer method as discussed earlier.
Good luck.

Similar Messages

  • Converting Document object into XML file

    I was wondering how to convert a document object to XML file? I have read the documentation about document and Node but nothing explains the procedure of the conversion. Ive been told that it can be done, but not sure how. I have converted an XML file into Document by parsing DocumentBuilder. Just not sure how to do the reverse. Any help appreciated.

    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer trans = tf.newTransformer();
    trans.transform(new DOMSource(yourDOMsRootNode), new StreamResult(new FileOutputStream(yourFileName)));or something a lot like that.

  • Saving multiples objects into a file

    I want to create a single file that has multiples things inside, like pictures (png) and texts. Does someone knows how it will be the structure of the binary file?
    I'm programming a draw software like photoshop, where my layers are BufferedImages. Theses bufferedImages must be saved into a file to re-open later and edit.
    Please I want just ideas....
    thanks

    If the objects that you store in your file are fairly independent of each other, one thing that comes
    to mind is to make your file a zip file of component files. That way you can use standard tools to examine
    it and edit it if you wish.
    Another thing to note is that if your file is largely a series of images, some image file formats,
    like tiff , jpeg and gif allow you to store sequences of images in one file.
    Here's a demo that creates a tiff file holding four images, then reads the file and displays the images.
    Stardard software like Kodak's "Imaging Preview" will allow you to flip through the images in the file.
    By the way, if you don't have readers/writers for format tiff, you can get them here.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class IOExample {
        public static void main(String[] args) throws IOException {
            String urlPrefix = "http://www3.us.porsche.com/english/usa/carreragt/modelinformation/experience/desktop/bilder/icon";
            String urlSuffix = "_800x600.jpg";
            int SIZE = 4;
            BufferedImage[] images = new BufferedImage[SIZE];
            for(int i=1; i<=SIZE; ++i)
                images[i-1] = ImageIO.read(new URL(urlPrefix + i + urlSuffix));
            File file = new File("test.tiff");
            file.delete();
            int count = writeImages(images, file);
            if (count < SIZE)
                throw new IOException("Only " + count + " images written");
            images = null;
            images = readImages(file);
            if (images.length < SIZE)
                throw new IOException("Only " + images.length + " images read");
            display(images);
        public static void display(BufferedImage[] images) {
            JFrame f = new JFrame("IOExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel p = new JPanel(new GridLayout(0,1));
            for(int j=0; j<images.length; ++j) {
                JLabel label = new JLabel(new ImageIcon(images[j]));
                label.setBorder(BorderFactory.createEtchedBorder());
                p.add(label);
            f.getContentPane().add(new JScrollPane(p));
            f.setSize(400,300);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        //suffix is "jpeg", "gif", "png", etc... according to your service providers
        public static ImageWriter getWriter(String suffix) throws IOException {
            Iterator writers = ImageIO.getImageWritersBySuffix(suffix);
            if (!writers.hasNext())
                throw new IOException("no writers for suffix " + suffix);
            return (ImageWriter) writers.next();
        public static ImageReader getReader(String suffix) throws IOException {
            Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
            if (!readers.hasNext())
                throw new IOException("no reader for suffix " + suffix);
            return (ImageReader) readers.next();
        public static int writeImages(BufferedImage[] sources, File destination) throws IOException {
            if (sources.length == 0) {
                System.out.println("Sources is empty!");
                return 0;
            } else {
                ImageWriter writer = getWriter(getSuffix(destination));
                ImageOutputStream out = ImageIO.createImageOutputStream(destination);
                writer.setOutput(out);
                writer.prepareWriteSequence(null);
                for(int i=0; i<sources.length; ++i)
                    writer.writeToSequence(new IIOImage(sources, null, null), null);
    writer.endWriteSequence();
    return sources.length;
    public static BufferedImage[] readImages(File source) throws IOException {
    ImageReader reader = getReader(getSuffix(source));
    ImageInputStream in = ImageIO.createImageInputStream(source);
    reader.setInput(in);
    ArrayList images = new ArrayList();
    GraphicsConfiguration gc = getDefaultConfiguration();
    try {
    for(int j=0; true; ++j)
    images.add(toCompatibleImage(reader.read(j), gc));
    } catch(IndexOutOfBoundsException e) {
    return (BufferedImage[]) images.toArray(new BufferedImage[images.size()]);
    public static String getSuffix(File file) throws IOException {
    String filename = file.getName();
    int index = filename.lastIndexOf('.');
    if (index == -1)
    throw new IOException("No suffix given for file " + file);
    return filename.substring(1+index);
    //make compatible with gc for faster rendering
    public static BufferedImage toCompatibleImage(BufferedImage image, GraphicsConfiguration gc) {
    int w = image.getWidth(), h = image.getHeight();
    int transparency = image.getColorModel().getTransparency();
    BufferedImage result = gc.createCompatibleImage(w, h, transparency);
    Graphics2D g = result.createGraphics();
    g.drawRenderedImage(image, null);
    g.dispose();
    return result;
    public static GraphicsConfiguration getDefaultConfiguration() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    return gd.getDefaultConfiguration();

  • How get data from business object to xml file

    Hi all,
    My new problem is ,,
    In my application, I have check list of selected business partners. In that , I want to save the checked oBusinessPartners complete information to an XML file(created dynamically),
    How to do?
    Thanks in advance
    shashi kiran

    Shashi Kiran,
    Can you explain me detail where
    you want to save check business partners in xml ?
    Jeyakanthan

  • Saving an object into  a file

    Hey all,
    I'm trying to save an object I have coded to a file on my hard-drive
    using an inner save() method.
    Though I realise I should put something in an output stream,
    I can't find a way to put my object into an input-stream. How do I do that? Using which classes?

    to save an object's state use: implements serializable
    http://java.sun.com/docs/books/tutorial/essential/io/objectstreams.html

  • Converting Dom Document object into XML file removes the DTD

    Hi All
    My xml is dtd. I have one xml file. i changed the node value after that i want to create a xml file with the same name. I created new xml file but i am not seeing the old dtd in the new file. This process is done with the help of jaxp.
    My code is given below
    File fileInput = new File("input.xml");
              File fileOutput = new File("output.xml");
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setExpandEntityReferences(false);
              DocumentBuilder builder = factory.newDocumentBuilder();
              Document document = builder.parse(fileInput);
              TransformerFactory tFactory = TransformerFactory.newInstance();
              Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "true");
              transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
              DOMSource source = new DOMSource(document);
              FileOutputStream fos = new FileOutputStream(fileOutput);
              StreamResult result = new StreamResult(fos);
              transformer.transform(source, result);
    Thanks in advance

    The Transformer API does not guarantee the preservation of that information. You may want to check the DOM L3 Load/Save package (http://java.sun.com/javase/6/docs/api/index.html). Alternatively, you may force things by setting the additional output properties 'doctype-public' and 'doctype-system'.

  • Serializing Java Objects to XML files

    Hi,
    We looking for SAP library which can serialize Java Objects into XML files.
    Can you point us were to find it ?
    We have found such open source library called "XStream" at the following link
    http://www.xml.com/pub/a/2004/08/18/xstream.html
    Is it allowed to use that library inside SAP released software ?
    Thanks
    Orit

    How about https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/83f6d2fb-0c01-0010-a2ba-a2ec94ba08f4 [original link is broken] [original link is broken]? Depends on your use cases...
    Both are supported in SAP NW CE 7.1.
    HTH!
    -- Vladimir

  • Store and load objects to XML files using DOM

    Hello everybody,
    a quick question for all of you.
    I'm designing a desktop application which requires a lot of custom objects to be stored into XML files and later reloaded from them. I'm planning to use DOM, creating an interface like this:
    public interface StorableAsDom
    // Create an object from a DOM tree
    static Object createFromDom(org.w3c.dom.Node root) throws InvalidDomException;
    // Get the DOM tree for an object
    org.w3c.dom.DocumentFragment getDomTree(org.w3c.dom.Document doc) throws DOMException;
    Then, every class which needs to be saved should implement the above interface. This way everything works fine.
    My question is: do you know any available java package which already provides similar functionalities?
    I'd like not to reinvent the wheel if I can; time is always a critical factor.
    Thanks in advance to all of you.
    Cheers
    marcocaco

    Hi,
    When I need object -xml binding, I usually have two methods -
    one for reading & one for writing (the "VOs" below stands for "Value Objects" [getters/setters & empty constructor only]):
    READ: loadXML (= XML2VOs)
    1.XML2DOM - this method can be generic
    2.DOM2VOs - populate your VOs from the DOM just obtained in 1.
    WRITE: saveXML (=VOs2XML)
    1.VOs2DOM - create a new DOM document from your VOs' fields.
    2.DOM2XML - this method can be generic
    It would be nice (but dificult & not very elegant) to make DOM2VOs & VOs2DOM generic. If such methods will be written, they should be combined with the XML2DOM & DOM2XML (resp.) & then you would have two generic methods XML2VOs & VOs2XML... (Alternativelly, you can get Sun's JAXB package which does object-xml binding but this is not part of the JDK 5)
    If what I have outlined above sounds like what you want to do, let me know if you want more details (eg. how the DOM2VOs would be implemented etc)...

  • GRC TCG - Importing a cusom business object via XML

    Hi ,
      I am trying to import a custom business object into GRC TCG 8.6.5 Version using the XML file . But , the import job completes with the error message :
    "oracle.apps.grc.common.job.JobExecutionException: Error occured during import" .
    I tried to find a sample XML file in UG/IG , but could not find any . So , i am not sure if there is any problem with the XML file structure i am using .
    Please let me know if you have any idea .
    I am attaching the XML file i am using for import . Also listing it below for quick reference -
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Custom_BO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
      <InvNum>100000</InvNum>
      <PayTerm>UPON RECEIPT</PayTerm>
    </record>
    <record>
      <InvNum>200000</InvNum>
      <PayTerm>UPON RECEIPT</PayTerm>
    </record>
    <record>
      <InvNum>300000</InvNum>
      <PayTerm>NET 30</PayTerm>
    </record>
    <record>
      <InvNum>400000</InvNum>
      <PayTerm>NET 45</PayTerm>
    </record>
    <record>
      <InvNum>500000</InvNum>
      <PayTerm>NET 60</PayTerm>
    </record>
    </Custom_BO>

    Is this the first time you imported a custom business object? You followed the steps from the guide on how to create the proper XML from Excel to import, correct?
    If you haven't seen how to do that yet, go to: Oracle Enterprise Governance, Risk and Compliance Documentation and download the Enterprise Transaction Controls Governor User Guide.
    Go to page 2-5 and read the section on Using Custom Objects.  This should get you started in the right direction.
    Also in the future you would want to post to the more active Oracle GRC forum at: Governance, Risk and Compliance (GRC) (MOSC)
    I hope that helps!
    Regards,
    Yasir

  • Can i download whole WD Abap scenario into XML File ?

    Hi,
    Experts,
    I want to download the WD( Web Dynpro ) Abap scenario into Xml file from one SAP server. by upload this xml file into another server(uploaded server) to create the WD abap scenario as it is in downloaded server. As like we download the report into xml using                              '  cl_gui_frontend_services ' class.
    through Transporting the request into that upload server i can do that but the thing is there is not communication between these systems. for that i am searching in this way.
    Thank you,
    Shabeer ahmed

    Hi Shabeer,
    This feature is not currently in the standard system. However there is a beta version of a plugin for exporting and importing Web Dynpro ABAP components.You would have to use the SAPLink program (ZSAPLINK) to export and import objects. Please go through this link to download the necessary stuff.
    [http://code.google.com/p/saplink/|http://code.google.com/p/saplink/]
    For any problems while uploading these nuggets into SAP you can post your queries [here|www.saplink.org].  Also refer to Thomas Jung's comments in [here|How to install the SAPlink plugins;.
    Regards,
    Uday

  • Outbound oracle data into xml file

    Hi Odie,
    Your previous inputs for xml inbound was working fine, in the similar way now I need outbound the oracle apps data into .xml file format. For that I've written one sample script like this. I thought of making use of the utl_file option in Oracle apps.
    declare
    l_log_handle UTL_FILE.FILE_TYPE;
    l_log_name varchar2(50);
    l_path_2 varchar2(40);
    l_global_file varchar2(50);
    l_time number:=1;
    cursor cur1 is
    select xmltype(cursor(select * from fnd_menus where rownum <101)) a from dual;
    --select menu_id from fnd_menus where rownum<100;
    begin
    BEGIN
    SELECT DECODE (INSTR (VALUE, ','),
    0, VALUE,
    SUBSTR (VALUE, 1, (INSTR (VALUE, ',', 1)) - 1)
    INTO l_path_2
    FROM v$parameter
    WHERE NAME = 'utl_file_dir';
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error while getting Unix Path ' || SQLERRM);
    END;
    l_log_name := 'XGBIZ_'||TO_CHAR (SYSDATE, 'YYMMDD')||l_time;
    l_log_name := CONCAT(l_log_name,'.xml');
    l_global_file := l_log_name;
    l_log_handle := UTL_FILE.FOPEN(l_path_2,l_log_name,'W');
    for cur2 in cur1 loop
    UTL_FILE.PUT_LINE(l_log_handle, cur2);
    end loop;
    utl_file.fclose_all;
    EXCEPTION
    WHEN UTL_FILE.INVALID_OPERATION THEN
    dbms_output.put_line('Invalid Operation For '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.INVALID_PATH THEN
    dbms_output.put_line('Invalid Path For '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.INVALID_MODE THEN
    dbms_output.put_line('Invalid Mode For '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    dbms_output.put_line('Invalid File Handle '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.WRITE_ERROR THEN
    dbms_output.put_line('Invalid Write Error '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.READ_ERROR THEN
    dbms_output.put_line('Invalid Read Error '|| l_global_file);
    UTL_FILE.FCLOSE_ALL;
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    dbms_output.put_line('Internal Error');
    UTL_FILE.FCLOSE_ALL;
    WHEN OTHERS THEN
    dbms_output.put_line('Other Error '||'SQL CODE: '||SQLCODE||' Messg: '||SQLERRM);
    UTL_FILE.FCLOSE_ALL;
    end;
    when running this script I am getting error
    ERROR at line 30:
    ORA-06550: line 30, column 2:
    PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
    ORA-06550: line 30, column 2:
    PL/SQL: Statement ignored
    if in the cursor declaration happen to use 'select menu_id from fnd_menus ' a plain record then it is successfully creating.
    If tried again revert to actual select statement ' select xmltype(cursor(select * from fnd_menus where rownum <101)) a from dual'
    then its erring out as above said.
    Please give me your valuable inputs in this regard.
    Thanks & Regards
    Nagendra

    Hi,
    There are multiple ways to generate XML documents from relational data.
    Here are some :
    -- SQL/XML functions : XMLElement, XMLAgg, XMLAttributes etc.
    -- DBMS_XMLGEN package
    select dbms_xmlgen.getXML('SELECT * FROM scott.emp')
    from dual;-- XMLType constructor over a REF CURSOR (the one you chose)
    select xmlserialize(document
             xmltype(
               cursor(
                 select *
                 from scott.emp
             as clob
    from dual;-- From a DBUriType
    select xmlserialize(document
             dburitype('/SCOTT/EMP').getXML()
             as clob
    from dual;-- From XQuery using ora:view function
    select xmlserialize(document
             xmlquery('<ROWSET>{ora:view("SCOTT","EMP")}</ROWSET>' returning content)
             as clob indent size = 1
    from dual;If a column is NULL in the result set, those methods (except XMLElement) won't create the corresponding element.
    There's an option available for the XQuery method, but only in version 11.2.
    So if you want to output empty elements, you'll have to use DBMS_XMLGEN with setNullHandling method :
    DECLARE
    ctx   DBMS_XMLGEN.ctxHandle;
    v_out CLOB;
    rc    SYS_REFCURSOR;
    BEGIN
    OPEN rc FOR
      SELECT *
      FROM scott.emp
    ctx := DBMS_XMLGEN.newContext(rc);
    DBMS_XMLGEN.setNullHandling(ctx, DBMS_XMLGEN.EMPTY_TAG);
    v_out := DBMS_XMLGEN.getXML(ctx);
    DBMS_XMLGEN.closeContext(ctx);
    CLOSE rc;
    DBMS_XSLPROCESSOR.clob2file(v_out, 'TEST_DIR', 'test_out.xml');
    END;
    I thought of making use of the utl_file option in Oracle apps.You could, but you might find DBMS_XSLPROCESSOR.clob2file procedure more convenient for that (see above).
    All you have to do is serializing the XML in a CLOB variable, and call the procedure.
    WHERE NAME = 'utl_file_dir';The "utl_file_dir" init. parameter is deprecated since 10g, use directory objects instead.

  • I received pictures in a dozen emails and saved each picture into one file in .pages.  I did not import the photos before doing this and now iPhoto won't recognize the pictures because they are in a .pages file.  How do I get the pics to iPhoto?

    I received a dozen pictures in a few emails and I saved them all into one file in pages.  I just copied and pasted.  I do not have the originals any longer.  Iphoto will not permit me to import the pictures as it does not recognize a .pages file, nor can I simply click and drag from the pages document to iphoto nor from pages to the desktop to iphoto.  How can I save each picture I guess back into a jpeg and then import them into iphoto or have i lost them to a pages document forever?  This is urgent as I need the pictures made into a book on iphoto for work by Friday!!!  Please advise!  Thank you.

    Greetings,
    Locate the Pages document wherever it's located on your computer and click once on it to highlight it.
    Go to File > Duplicate to make a backup copy of the file.
    Click once again on the file to highlight it.
    Go to File >  Get Info
    In the "Name & Extension" category remove the ".pages" extension and put in ".zip".
    Close the info window and double-click the now renamed pages file (zip file now).It will decompress into a folder which contains all the base components including all the images you added.  These can be dragged onto the iPhoto icon to import them.
    Hope that helps.

  • Why we need to conver Context  Node data into XML file----Export to Excel

    Hi All,
    Let me clarify my dought........today i have gone through the concept of  "Exporting Context Data Using the Webdynpro Binary cache" in SAP Online Help.
    From the SAP Online Help pdf document, i have found that, the context node data has been converted first in to XML file,after that file had been stored in the web dynpor binary cache...bla....bla.........
    Here my qtn is why they had converted context node data into XML file. With out doing that can not we export context node data to excel file..?
    Regards
    Seshu
    Edited by: Sesshanna D on Dec 19, 2007 7:25 AM

    Hi Sesshanna,
    it is not neccessary to do that but xml has the advantage, that it can be easily transformed into every output format that might occur in later project stages.
    If it's simply about blowing out some Excel, I suggest using an OSS library such as jexcelAPI or Jakarta POI and building the Excel how you need it.
    regards,
    Christian

  • Dynamically create Value Objects from XML file

    Hi
    I want to create a value object from Xml file dynamically,like in the xml file i have the name of the variable and the datatype of the variable.is it possible do that,if so how.

    Read about apache's Digester tool. This is part of the Jakartha project. This tool helps in creating java objects from the XML files. I am not sure, if that is what u r looking for.

  • Insert Encoding tag into xml file. ?xml version="1.0"?

    I am using oracle 10g.
    I am using dbms_xmlgen.getxml function to generate xml data for oracle tables. I use utl_file to write data back into xml file.
    Oracle is generating the file in the following manner...
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <RSLT_ID>1</RSLT_ID>
    </ROW>
    </ROWSET>
    I want to change the following xml header to have encoding information in it as follows...
    <?xml version="1.0" encoding = "AL32UTF8"?>
    How do I achieve that?
    Any suggestions?

    I want to change the following xml header to have encoding informationIn 10g I think you could use a xmlroot hack:
    SQL> select xmlroot(xmlelement(e, dummy), version '1.0" encoding="AL32UTF8') xml from dual
    XML                                                    
    <?xml version="1.0" encoding="AL32UTF8"?>              
    <E>X</E>                                               
    1 row selected.

Maybe you are looking for