Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

update an xml file with jaxb and accessing to its elements

Wed Jul 15, 2009 10:47 am

HI

I am working with jaxb .I has get my java classes from my schema xml .
My root element is binded to a java classs with getters and setters for its attributes and a method that returns a list of the other elements .
Code:
public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }


I have an xml file that contains just the basic elements and i want to insert elemets and values of attributes .I succed to add attributes to my root element but how can i acceed by this method to other elements and use its methods? IDE:   Netbeans 6.5.1 Technology:  jaxb



Re: update an xml file with jaxb and accessing to its elements

Thu Jul 16, 2009 6:00 am

jaxb/unmarshall-from-xml-using-jaxb-t5294.html
jaxb/marshal-java-object-to-xml-file-t5293.html

Re: update an xml file with jaxb and accessing to its elements

Thu Jul 16, 2009 8:37 am

My problem that that the method getContent return different objects which are nodes .
I can just access to the root by :
Code:
root =(root)u.unmarshal(new FileInputStream("A.xml")

i want to access to the methods of the binded nodes .

Re: update an xml file with jaxb and accessing to its elements

Thu Jul 16, 2009 9:51 am

When i access to the first node(E) just after the root and i want to display the name of the it first subnode with this code


Code:
System.out.println(E.getContent();.get(0).getClass().getName());


I get in output this:

javax.xml.bind.JAXBElement


Please i need an urgent help

Re: update an xml file with jaxb and accessing to its elements

Sun Jul 19, 2009 8:31 am

am just wondering . we don't you try to do the following :

Code:
System.out.println(E.getContent().get(0).getClass().getName());


did u tried to do the following
Code:
System.out.println(E.getContent().getClass().getName());


Re: update an xml file with jaxb and accessing to its elements

Tue Jul 21, 2009 7:01 am

i HAVE RESOLVED tHE PROBLEM :

List Li=E.getContent();
JAXBElement D=(JAXBElement)Li.get(0);//it returns jaxb
NOEUD Da=( NOEUD)D.getValue();

thanks a lot

Post a reply
  Related Posts  to : update an xml file with jaxb and accessing to its elements
 update an xml file with jaxb     -  
 Load file and update content using AJAX and JQuery     -  
 php Accessing a Property from Within a Method     -  
 Dynamically Setting and Accessing Variables     -  
 Accessing files in remote server (unix/windows) using JSP     -  
 Unmarshall From XML using JAXB     -  
 XML using JAXB API in java     -  
 how to use enum in jaxb unmarshalling     -  
 insert a namespace in a tag with jaxb     -  
 update query example     -  

Topic Tags

Java XML, Java JAXB