Help on creating and deleting xml child elements using Toplink please.

Hi there,
I am trying to build a toplink xml demo illustrating toplink acting as the layer between my java code and an xml datasource.
After pulling my custom schema into toplink and following the steps in http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp3/howto/jaxb/index.htm related to
Click on Mapping Workbench Project...Click on From XML Schema (JAXB)...
I am able to set up java code which can run get and sets against my xml datasource. However, I want to also be able create and delete elements within the xml data for child elements.
i.e. in a simple scenario I have a xsd for departments which has an unbounded element of type employee. How does toplink allow me to add and or remove employees in a department on the marshalled xml data source? Only gets and sets for the elements seem accessible.
In my experience with database schema based toplink demos I have seen methods such as:
public void setEmployeesCollection(Collection EmployeesCollection) {
     this.employeesCollection = employeesCollection;
Is this functionality available for xml backended toplink projects?
cheers
Nick

Hi Nick,
Below I'll give an example of using the generated JAXB object model to remove and add a new node. The available APIs are defined in the JAXB spec. TopLink also supports mapping your own objects to XML, your own objects could contain more convenient APIs for adding or removing collection members
Example Schema
The following XML Schema will be used to generate a JAXB model.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
     elementFormDefault="qualified" attributeFormDefault="unqualified">
     <xs:element name="department">
          <xs:complexType>
               <xs:sequence>
                    <xs:element ref="employee" maxOccurs="unbounded"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
     <xs:element name="employee">
          <xs:complexType>
               <xs:sequence>
                    <xs:element name="name" type="xs:string"/>
               </xs:sequence>
          </xs:complexType>
     </xs:element>
</xs:schema>---
Example Input
The following document will be used as input. For the purpose of this example this XML document is saved in a file called "employee-data.xml".
<department>
     <employee>
          <name>Anne</name>
     </employee>
     <employee>
          <name>Bob</name>
     </employee>
</department>---
Example Code
The following code demonstrates how to use the JAXB APIs to remove the object representing the first employee node, and to add a new Employee (with name = "Carol").
JAXBContext jaxbContext = JAXBContext.newInstance("your_context_path");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File file = new File("employee-data.xml");
Department department = (Department) unmarshaller.unmarshal(file);
// Remove the first employee in the list
department.getEmployee().remove(0);
// Add a new employee
ObjectFactory objectFactory = new ObjectFactory();
Employee newEmployee = objectFactory.createEmployee();
newEmployee.setName("Carol");
department.getEmployee().add(newEmployee);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(department, System.out);---
Example Output
The following is the result of running the example code.
<department>
     <employee>
          <name>Bob</name>
     </employee>
     <employee>
          <name>Carol</name>
     </employee>
</department>

Similar Messages

  • CREATE and DELETE operations in MI7.1 for PDA

    Hi,
    We are developing a sample scenario for PDA in 7.1. Problem is we are able to implement GETLIST, GETDETAIL and MODIFY operations but not able to implement CREATE and DELETE operations. For GETLIST and GETDETAIL i have created queries. Modify is also simple (i am creating a form to edit and commiting data once i click on save). But to implement CREATE and DELETE we dont have any reference.
    Regards,
    Vinay

    Hi,
    Now i know the answer
    There is a typed method on the service component model class for root node creation. Example for binding a new root instance to a context node:
    wdContext.nodeCurrentEmployee().bind(Collections.singleton(model.createEmployeeSdoEmployee()));
    where model is your webdynpro model.Employee is a context node model bounded to Employee model class.This node has to be manually created in context(and then can be context mapped and bound to elements in view)
    wdContext.nodeCurrentEmployee().setLeadSelection(0);
    Creating a child is done on the root itself, but persisting it is a two step process:
    address = employeeRootNode.createNewAddresss(); <- this only creates the instance in memory
    where employeeRootNode is the model object for which the child has to be created. If the element for which the child has to be created exists in context then it can be got by
    wdContext.nodeEmployee().currentEmployeeElement.model()
    employeeRootNode.addToAddresss(address);  <- this persists the new instance
    wdContext.nodeCurrentAddress().bind(Collections.singleton(address));
    wdContext.nodeCurrentAddress().setLeadSelection(0);
    Delete of a root is also done on the sc model class:
    model.removeEmployeeSdoEmployee(employeeRootNode);
    Delete of a child is done one the root:
    employeeRootNode.removeFromAddresss(address);
    Hope this helps.
    Regards,
    Vinay
    Edited by: Vinay TS on May 5, 2008 8:31 AM

  • How to create and delete an Endeca application in Windows

    HI,
    can you please help me in ,
    how to create and delete an Endeca application inWindows machine not in Linux Machine.
    Thanks.....

    Hi,
    Steps to create an Endeca Application are clearly given in Getting Started Guide.
    http://docs.oracle.com/cd/E38680_01/Common.311/pdf/GettingStarted.pdf (Chapter 6 : Deploying a Reference Application)
    If you want to create an endeca application so as to integrate with Product Catalog system such as ATG using ATG 10.1.1 or above , then create an endeca application using the discover-data-catalog-integration reference application. Steps for doing this are documented in ProductCatalogDTGuide
    http://docs.oracle.com/cd/E38679_01/ToolsAndFrameworks.311/pdf/ProductCatalogDTGuide.pdf (Deploying the Product Catalog Application)
    To delete an Endeca Application that you have created in Windows/linux
    1. Navigate to the control directory of the application that you want to remove and execute the script
    runCommand.bat --remove-app (Removes the provisioning information with EAC admin console)
    2. Remove the instance configuration files for the application using the emgr_update command line utility
    emgr_update.bat host localhost:8006 app_name My_app action remove_all_settings prefix My_prefix
    3. You can then explicitly delete the directory in the Endeca_apps directory where you have initially created your application.
    If you are using discover-data-catalog-integration, you can remove the CAS Record Store Instances by navigating to CAS/bin directory and executing
    ./component-manager-cmd.sh delete-component -n {YOUR_APP_RECORD_STORE_NAME}
    Thanks,
    Shabari

  • BAPI for purchase order .. to create and delete confirmation

    HI Gurus
    I need to create and delete PO(Purchase order) confirmation in SAP 4.7 R3 .
    Please let me know which BAPI i can use for .. in SAP 4.7
    1. Create PO confirmation
    2. Delete PO confirmation
    Many thanks and regards
    Sandeep Sharma

    Hi Sandeep,
    In SAP 4.7 R3 & ECC 5.0. we don't have BAPI to delete / create PO confirmatons.
    Use this FM for both : ME_CONFIRMATION_UPDATE
    In addition to above , we need to use this FM : ME_CONFIRMATION_REDISTR_ITEMS , for PO item update in MD04 transaction.
    In addtion to above 2 FM, you need to used Change doucment FM for write log data.
    Thanks.

  • How to identify combination of created and deleted Bank Details

    Hi Experts,
    I will develop a report similar to standard report RFKABL00. The requirement is to display the date, time, vendor number, vendor name, changed by, field name, company, purchasing org, new value and old value everytime a user make a change on the bank details (Bank Key and Bank Account only in XK02).
    The content of field name will be either Bank Key or Bank Account with its corresponding old and new value. Using transaction XK02, I tried to replace the Bank Account of the vendor and saved the data. The created and deleted values can be found in CDPOS using: objectclas: kred, tabname: lfbk and fname: key; but it is difficult to identify the correct combination of deleted and created values. I observed that for non-key fields in LFBK table there are entries for old and new values but for key fields like bank key and bank account they have nothing.
    How will we identify the correct combination of deleted and created values if there are many entries in CDPOS?

    Murali,
    As already specified in your previous thread. You can get the id using source code. or extend the CO and print the value of s2.
    Regards,
    Gyan
    www.gyanoracleapps.blogspot.com
    www.querenttech.com

  • How to create new Custom XML Report without using Form Builder

    Hi,
    What are the steps to create new Custom XML Report without using Report Builder ?
    Thanks and Regards,
    Abhi

    Hi,
    Steps we now follow
    1)Create Data Model in Reports Builder
    2)Create xml
    3)Insert xml in Publisher to build Fomat
    4)FTp rdf
    5)Create Data Definition and Template
    6)Create executable and Concurrent Program
    Is there any way we can build reports without use of Report Builder ? By writing PL SQL Package for Before Report and After Report etc ...
    Thanks and Regards,
    Abhijit Rode

  • How to create and edit a .ini file using java

    Hi All...
    Pls help me in creating and editing an .ini file using java...
    thanks in advance
    Regards,
    sathya

    Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         private static Properties props;
         public static void main(String[] args) throws IOException {
              File file = new File("test.ini");//This is out ini file
              props = new Properties();//Create the properties object
              read(file);//Read the ini file
              //Once we've populated the Properties object. set/add a property using the setProperty() method.
              props.setProperty("testing", "value");
              write(file);//Write to ini file
         public static void read(File file) throws IOException {
              FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
              props.load(fis);//load the ini to the Properties file
              fis.close();//close
         public static void write(File file) throws IOException {
              FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
              props.store(fos, "");//write the Properties object values to our ini file
              fos.close();//close
    }

  • How to delete parent child relation in Toplink

    Hi All,
    I have 3 tables A,B,C.
    In Table A ,I am saving record.
    Table B & C has parent child relation.
    B-->Parent
    C-->Child
    So I want to save records in Table A.
    And delete from child(C) 1st then from parent(B).
    I m writing my code as,
    em.getTransaction().begin();
    em.persist(Table A);//save in Table A
    em.remove(em.merge(Table B));//Remove from Parent
    But how to delete records from child table then from parent table.
    Thanks
    Sandip

    If you have a @OneToOne relationship between two entities, the join column information is used to order the SQL when you remove two entities. For example, if I have:
    @Entity
    public class Employee implements Serializable {
         @OneToOne
         @JoinColumn(name="ADDR_ID")
         private Address address;
    ...Then the following code runs regardless of the order of the remove calls.
              em.getTransaction().begin();
              Employee parent = new Employee();
              Address child = new Address();
              parent.setAddress(child);
              em.persist(parent);
              em.persist(child);
              em.getTransaction().commit();
              em.getTransaction().begin();
              parent = em.merge(parent);
              child = em.merge(child);
              // order of next two statements unimportant
              em.remove(parent);
              em.remove(child);
              em.getTransaction().commit();If I don't remove the parent and just the child I get the same error you do because of the FK from Employee to Address.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • I was on facebook and deleted an icon by using the right-click menu but then all my pictures and all profile pictures, could no longer be seen. I was able to view them in Explorer so this is something I did in Firefox. How can I unblock a site?'

    '''I was on facebook and deleted an icon by using the right-click menu but then all my pictures and all profile pictures, could no longer be seen. I was able to view them in Explorer so this is something I did in Firefox. How can I unblock a site?'''

    If you select that right-click context menu entry then you block all images from that domain and not one specific image, so do not use that.
    * Check the exceptions in Tools > Options > Content: Load Images > Exceptions (e.g. sphotos.ak.fbcdn.net)
    You can use these steps to check if images are blocked:
    * Open the web page that has the images missing in a browser tab.
    * Click the website favicon ([[Site Identity Button]]) on the left end of the location bar.
    * Click the "More Information" button to open the "Page Info" window with the Security tab selected (also accessible via "Tools > Page Info").
    * Go to the <i>Media</i> tab of the "Tools > Page Info" window.
    * Select the first image link and scroll down through the list with the Down arrow key.
    * If an image in the list is grayed and there is a check-mark in the box "<i>Block Images from...</i>" then remove that mark to unblock the images from that domain.

  • Getting XML child elements

    Dear Indesign scripters,
    This script is making from all the XML tags ParagraphStyles.
    But it refuses to take the child elements. Do I have to use XPath expression? And how?
    function main() { 
      var xes, n, doc, ps, xe; 
      if ( !app.documents.length ) return; 
      doc = app.activeDocument;
      xes = doc.xmlElements[0].xmlElements; 
      n = xes.length; 
      while ( n-- ) { 
      xe = xes[n];
      st = doc.paragraphStyles.itemByName (xe.markupTag.name ); 
      !st.isValid && doc.paragraphStyles.add({name:xe.markupTag.name}); 
    main();
    The XML
    <Workbook> 
         <Element_A_01> 
              <Element_A_01></Element_A_01> 
         </Element_A_01> 
         <Element_B_02> 
              <Element_B_02></Element_B_02> 
         </Element_B_02> 
    </Workbook>
    Greetings from Holland

    The code creates two paragraph styles namely Element_A_01 and Element_B_02. These two are created for the immediate child nodes of the Workbook node. Now it seems that you are trying to create pstyles for all the nodes in the XML, which in your case would still be these two as Element_A_01 has a child node that is also named Element_A_01 and the same is the case for Element_B_02.
    If i get your point right then you need to create 4 pstyles if all the nodes have different names, but that is not working. For this you will have to recursively traverse each node that you get from the code xes[n].
    The code be something like this
    function main() {   
      var xes, n, doc, ps, xe;   
      if ( !app.documents.length ) return;   
      doc = app.activeDocument; 
      xes = doc.xmlElements[0].xmlElements; //This gives the immediate child nodes of the Workbook node, hence the length in the next statement is 2  
      n = xes.length;   
      while ( n-- ) {   
      xe = xes[n];   //Here you need to recursively traverse the node xe
      //The no of child elements of xe can be obtained as xe.xmlElements.length
      //First element can be obtained by xe.xmlElements[0]
    main();
    Hope this solves the issue

  • Search for, edit, and delete XML tag (Adobe InDesign Server CS5)

    Hi all,
    I'm working with Indesign Server CS5 and JavaScript, though having some trouble coming up with a solution to a problem...
    I need to build a JS script (called through SOAP) that will enable me to search an InDesign file for a given XML tag.
    Upon finding the XML tag, if the 'action' variable is set to delete, it should delete the tag and its contents.
    If the action is set to edit, it should change the contents of the tag to some user-specified content.
    The primary caveat is that the XML tag is variable, as is the XML structure of the InDesign file.
    Here's what I have in mind, in pseudocode:
    function findXMLTag(tag, action) {
         app.searchForTag(tag);
         if (tagIsFound) {
              if (action == "delete") {
                   tag.delete;
              } else if (action == "edit") {
                   tag.contents = "Updated content";
    Any help would be greatly appreciated!
    Thanks,
    Ben Kay

    'searchForTag' can be implemented as a recursive function.
    Recursion is defined like this: I thought, "I'll just search this forum for 'recursion'." The first post I found was one of my own, suggesting that the poster should search the forum for 'recursion'.
    Here is an example: find the XML Element [<email>]
    And another: Remove xml element using JS[CS3] (read carefully, as the OP got stuck on how to successfully remove an element and continue)
    And one, using XML Rules -- which I'm totally unfamiliar with, but may work for you: Changing Values in XML tags

  • HOw to create a text file in the given path and delete it after the use?

    Hi all,
    I am trying to create a text file at the given path and delete the created file after the use.
    I am using following code.:
    import java.io.*;
    // write binary data as characters
    public class RanIO {
                                            public static void main(String f[])
                                                      // First illustrate append
                                                      String lineSep = "\n";
                                                      try {
                                                                     File temp= new File("C:/Ash","cute.txt");
                                                      boolean ch=temp.createNewFile();
                                                      if(ch)
                                                           System.out.println("file created");
                                                      else
                                                      System.out.println("file Not created");
                                                      //writing to file
                                                 /*     PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
                                                      p.print("Emp NO");
                                                      p.close();*/
                                                                // Open fileWriter in append mode
                                                                               FileWriter fos = new FileWriter(temp, true);
                                                                               BufferedWriter bw = new BufferedWriter(fos);
                                                                               PrintWriter pw = new PrintWriter(fos);
                                                                               double d=550;
                                                                          // lineSep = System.getProperty("line.separator");
                                                                          pw.print("Hello");
                                                                          //pw.print( lineSep );
                                                                          pw.print( d );
                                                                          pw.close();
                                  boolean det=temp.delete();
                                                 if(det)
                                                      System.out.println("File deleted");
                                                 else
                                                      System.out.println("File not deleted");
                                                 } catch (IOException ioe)
                                                                System.out.println( "Append IO error:" + ioe );
    My problem:
    1)
    I am not able to write to the file. I want to know, where i am going wrong.
    It is giving error message like
    "Canot resolve Symbol: temp,"
    But, FileWriter Constructor should accept a File type parameter.
    here temp is a file parameter.
    If i am not using file=new file();
    i can't delete the file after the use. i.e if i use
    PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
    how can i delete cute.txt after the use?
    2)
    I am not able to write to the text file. file is created but, a blank file.
    "Hello" is not written into the text file.
    can anyone help me in this regard
    Thanks in advance
    Ashvini

    Thank you Ram,
    But, i want to create a text file in Append mode.
    for that i used
    FileWriter fos = new FileWriter(temp,true); But, it is not accepting FileWriter constructor in
    this format. if i use
    FileWriter fos = new
    FileWriter("c:/ash/cute.txt",true); it works fine. !!!!!Here's the javadoc
    public FileWriter(File file,
    boolean append)
    throws IOExceptionConstructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
    Parameters:
    file - a File object to write to
    append - if true, then bytes will be written to the end of the file rather than the beginning
    Throws:
    IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
    Since:
    1.4
    Are you using jdk.13 or lower ?
    >
    ONe more doubt, Does flush method deletes a file?
    if not, then i need to use
    File temp=new File("c:/ash/cute.txt");
    FileWriter fos = new FileWriter(temp,true); //which
    is again a problem
    if(temp.delete())
    out.println("File is deleted");
    }I don't know whether i am taking it wrong ! or
    anything wrong with my coding ! but, after creating
    and writing data into a text file. I must delete it
    as it contains confidential informations.
    Regards,
    Thanks.'flush' writes to a file immediately. Else you should explicitly call 'flush' to write contents from buffer to underlying source.
    javadoc again
    PrintWriter
    public PrintWriter(Writer out,
    boolean autoFlush)Create a new PrintWriter.
    Parameters:
    out - A character-output stream
    autoFlush - A boolean; if true, the println, printf, or format methods will flush the output buffer
    cheers,
    ram.
    Question; What do you gain by opening a file, writing to it and deleting it in the same program ?

  • Creating and deleting users using AM Client SDK

    Hi,
    I was wondering if anyone could tell me how to create and/or delete users from Access Manager from a standalone application using the AM Client SDK? From what I have read this can be done using the AMStoreConnection class but I can't find any examples on how to use this class to add and delete users. The only examples I have found is how to retrieve data from AM. I need to keep AM and the underlying directory server in sync with another identity datastore so I need to build a process in Java to do this. Any help is appreciated.
    Thanks
    -Jeff

    Lets assume we have a HR system and the user has got deleted in the system, the HR system drop a CSV file to a specified location with the details of the user to be deleted from the IDM system . Now the CSV GTC connector would need to read the record and delete the user .
    This can be done , I have done this using API calls , but i assume that there would be someway of doing this using the OOB GTC .I think we need to set the correct value for the status field to do this ..
    I am not sure what status to set.

  • Problem with creating and deleting row in table

    Hi
    I'm using JDev11.1.1.2.0. I have a table "A" with primary key X -> CHAR(1). I have created Entity and ViewObject (with the primary key X).
    I created an editable Table with CreateInsert and Delete actions.
    When I click Insert, a new record is added and I enter some data. Then I move selection to some other row, and return back to the new row. When I press Delete, It does not delete the new row, but the previous one selected.
    In the console, when I navigate back two the new added record: <FacesCtrlHierBinding$FacesModel><makeCurrent> ADFv: No row found for rowKey: [oracle.jbo.Key[null ]].
    I tried the same scenario with a different table, that has RowID as a primary key and it works correctly.
    Any Idea why this is happening ? I suppose it's connected somehow with the primary key.
    Thanks
    agruev
    Edited by: a.gruev on Nov 26, 2009 9:47 AM

    I changed my entity: unchecked the X column to be primary key added RowID as a primary key. Now it works.
    What's wrong with my CHAR(1) as a primary key ?
    I also tried to add a Refresh button:
      <af:commandButton text="Refresh" id="cb3"/>and in the table add a partialTarget to the button. Now when I add new row and press the Refresh button - then it works.
    So it seems that the problem is when I add new row and enter data, the table is not refreshed and the row is missing it's primary key.
    Any solutions?
    Edited by: a.gruev on Nov 26, 2009 4:18 PM

  • Help with creating a new XML file from an existing DOM tree!!

    i want to create a new XML file from an existing DOM tree
    i used this code to create a new document:
    static public Document createDocument(String fileName) throws ParserConfigurationException//,IOException,SAXException
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setIgnoringComments(true);
                   factory.setIgnoringElementContentWhitespace(true);
                   factory.setValidating(true);
                   DocumentBuilder builder =factory.newDocumentBuilder();
                   return builder.newDocument();
    //          handle exception creating DocumentBuilder
              catch ( ParserConfigurationException parserError ) {
                        throw new ParserConfigurationException();
              }then i used this code to transform the DOM :
    public void exportDocument(Document document) {
              try {
                   Source xmlSource = new DOMSource( document );
                   Result result = new StreamResult( System.out );
                   TransformerFactory transformerFactory =
                        TransformerFactory.newInstance();
                   Transformer transformer =transformerFactory.newTransformer();
                   transformer.setOutputProperty( "indent", "yes" );
                   transformer.transform( xmlSource, result );
           //then catching the exceptions
    But the file was not created and i didn't find where can i specify the DTD that the XML file should use and where can i enter the name of the XML file itself
    Another questoin can i write a DTD file dynamically during the execution of the program??

    Cross-post: http://forum.java.sun.com/thread.jspa?threadID=784467&messageID=4459240#4459240

Maybe you are looking for