You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by acec acec <to...@yahoo.ca> on 2009/01/14 21:56:45 UTC
Betwixt: How can I change name during output?
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
Re: Betwixt: How can I change name during output?
Posted by acec acec <to...@yahoo.ca>.
I solved my problem by adding:
beanWriter.getXMLIntrospector().getConfiguration().setElementNameMapper(new CapitalizeNameMapper());
--- On Wed, 1/14/09, acec acec <to...@yahoo.ca> wrote:
> From: acec acec <to...@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