You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by sol myr <so...@yahoo.com> on 2009/09/09 17:27:39 UTC

[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.


      

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

Posted by sol myr <so...@yahoo.com>.
Thanks so much, that's just what I was looking for :)

--- On Wed, 9/9/09, Cezar Andrei <ce...@oracle.com> wrote:

From: Cezar Andrei <ce...@oracle.com>
Subject: RE: [xmlbeans] Dynamically renaming an element in XmlObject?
To: user@xmlbeans.apache.org
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:solmyr72@yahoo.com] 

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

To: user@xmlbeans.apache.org

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. 
  
  
 


   





 




      

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

Posted by Cezar Andrei <ce...@oracle.com>.
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:solmyr72@yahoo.com] 
Sent: Wednesday, September 09, 2009 10:28 AM
To: user@xmlbeans.apache.org
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.