Thanks so much, that's just what I was looking for :)

--- On Wed, 9/9/09, Cezar Andrei <[email protected]> wrote:

From: Cezar Andrei <[email protected]>
Subject: RE: [xmlbeans] Dynamically renaming an element in XmlObject?
To: [email protected]
Date: Wednesday, September 9, 2009, 2:13 PM




 
 

 







Hi, 

   

Take a look at the XmlCursor interface,
with it you have low level access to the xml representation, you can
create/modify instances that don’t have a schema definition. 

   

Renaming elements is not possible, but in
your case, you can create a new doc with one element AAA and than copy the
contents of your original employee element, ending up with the document you’re
looking for. 

   

Cezar 

   











From: sol myr
[mailto:[email protected]] 

Sent: Wednesday, September 09,
2009 10:28 AM

To: [email protected]

Subject: [xmlbeans] Dynamically
renaming an element in XmlObject? 



   


 
  
  Hi, 
  
     
  
  
  Given some XmlObject, is it possible to dynamically
  rename its root XML element? 
  
  
  Details:  
  
  
     
  
  
  1) I have and XSD with ComplexType: 
  
  
  <complexType name="Employee"> 
  
  
     <element name="salary"
  type="string"/> 
  
  
  </<complexType> 
  
  
  
     
  
  
  2) I need to create an XmlObjects, but dynamically
  rename its root XML tag. 
  
  
  I wish I could just write: 
  
  
  XmlObject e1=Employee.Factory.newInstance(); 
  
  
  e.setSalary("1000"); 
  
  
  e.setRootXmlTag("AAA");  // Wishful
  thinking - not a real code 
  
  
  // Now e.xmlText() should be:
  <AAA><salary>1000</salary></AAA> 
  
  
     
  
  
  3) I know that if the xml tag name (<AAA>) is
  known in advance, I can declare an XSD Element: 
  
  
  <element name="AAA" type="EmployeeType"/> 
  
  
  And XmlBeans will easily generate corresponding
  XmlObjects, with <AAA> root. 
  
  
     
  
  
  4) But what if the xml tag name is totally dynamic
  (e.g. extracted at runtime from a user's request)? Is there any way for me to
  control the XML tag name? 
  
  
  
     
  
  
  Thanks very much. 
  
  
 


   





 




      

Reply via email to