commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acec acec <tomcata...@yahoo.ca>
Subject Betwixt: How can I change <tag> name during output?
Date Wed, 14 Jan 2009 20:56:45 GMT
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


Mime
View raw message