commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acec acec <tomcata...@yahoo.ca>
Subject Re: Betwixt: How can I change <tag> name during output?
Date Wed, 14 Jan 2009 21:53:21 GMT
I solved my problem by adding:

beanWriter.getXMLIntrospector().getConfiguration().setElementNameMapper(new CapitalizeNameMapper());


--- On Wed, 1/14/09, acec acec <tomcatacec@yahoo.ca> wrote:

> From: acec acec <tomcatacec@yahoo.ca>
> Subject: Betwixt: How can I change <tag> name during output?
> To: user@commons.apache.org
> Received: Wednesday, January 14, 2009, 3:56 PM
> I defined a class as the following:
> public class VendorQueryRq {
> 	private int requestID;
> 
>         public int getRequestID() {
> 		return requestID;
> 	}
> }
> Then I am using the following code to covert the instance
> into xml:
> 
>         StringWriter outputWriter = new StringWriter(); 
> 
>         BeanWriter beanWriter = new
> BeanWriter(outputWriter);
>         
>         beanWriter.enablePrettyPrint();
>        
> beanWriter.getBindingConfiguration().setMapIDs(false);
> 
>         VendorQueryRq request = new VendorQueryRq();
>         request.setRequestID(11);
>         msgsRq.setVendorQueryRq(request);
> 
>         beanWriter.write(request);
>         System.out.println(outputWriter.toString());
> 
> Here is the output:
>   <VendorQueryRq>
>     <requestID>11</requestID>
>   </VendorQueryRq>
> 
> The output is good, which uses class name as tag
> name(VendorQueryRq).
> 
> Then I defined another class, which includes one
> VendorQueryRq attribute:
> public class QBXMLMsgsRq {
> 	private String onError;
> 
> 	private VendorQueryRq request;
> 
> 	public String getOnError() {
> 		return onError;
> 	}
> 
> 	public void setOnError(String onError) {
> 		this.onError = onError;
> 	}
> 
> 	public VendorQueryRq getVendorQueryRq() {
> 		return request;
> 	}
> 
> 	public void setVendorQueryRq(VendorQueryRq request) {
> 		this.request = request;
> 	}
> }
> Then I use the following code to print out xml:
>         StringWriter outputWriter = new StringWriter(); 
>         BeanWriter beanWriter = new
> BeanWriter(outputWriter);
>         
>         beanWriter.enablePrettyPrint();
>        
> beanWriter.getBindingConfiguration().setMapIDs(false);
> 
>         QBXMLMsgsRq msgsRq = new QBXMLMsgsRq();
>         msgsRq.setOnError("stopOnError");
> 
>         VendorQueryRq request = new VendorQueryRq();
>         request.setRequestID(11);
>         msgsRq.setVendorQueryRq(request);
> 
>         beanWriter.write(msgsRq);
>         
>         System.out.println(outputWriter.toString());
> 
> Now, xml output is the following:
>  <QBXMLMsgsRq>
>     <onError>stopOnError</onError>
>     <vendorQueryRq>
>       <requestID>11</requestID>
>     </vendorQueryRq>
>   </QBXMLMsgsRq>
> 
> But it use <vendorQueryRq> instead of
> <VendorQueryRq>, How can I change
> <vendorQueryRq> into <VendorQueryRq>?
> 
> Thanks a lot.
> 
> 
> 
>      
> __________________________________________________________________
> Yahoo! Canada Toolbar: Search from anywhere on the web, and
> bookmark your favourite sites. Download it now at
> http://ca.toolbar.yahoo.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail:
> user-help@commons.apache.org


      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites.
Download it now at
http://ca.toolbar.yahoo.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message