Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove namespace prefix from XmlBean

811879Oct 20 2011 — edited Dec 7 2011
Hi,

I am currently generating xml from fpml xsd using XBean. I've changed the default namespace using the following code.

XmlCursor cursor = em.newCursor();
if (cursor.toFirstChild()) {
String location = "XYZ_RM_9-0 /xmls/XYZ/XYZ_RM_9-0.xsd " +"\n"+ "XYZ_Catching_9-0 /xmls/XYZ/XYZ_Catching_9-0.xsd "+"\n"+
"http://schemas.xmlsoap.org/soap/envelope/ /xmls/XYZ/soap-envelope.xsd "+"\n"+
"http://www.fpml.org/2010/FpML-4-9 /xmls/XYZ/fpml-main-4-9.xsd";

cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance","schemaLocation",""),location);
cursor.insertNamespace("fpml", "http://www.fpml.org/2010/FpML-4-9");
cursor.insertNamespace("mtc", XYZ_Catching_9-0");
cursor.insertNamespace("rm", "XYZ_RM_9-0");
cursor.insertNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");
cursor.dispose();
}


When I generated the xml it is giving the following output(partially given):


<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fpml="http://www.fpml.org/2010/FpML-4-9"
xmlns:mtc="XYZ_Catching_9-0" xmlns:rm="XYZ_RM_9-0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="XYZ_RM_9-0 /xmls/XYZ/XYZ_RM_9-0.xsd XYZ_Catching_9-0 /xmls/XYZ/XYZ_Catching_9-0.xsd http://schemas.xmlsoap.org/soap/envelope/ /xmls/XYZ/soap-envelope.xsd http://www.fpml.org/2010/FpML-4-9 /xmls/XYZ/fpml-main-4-9.xsd">
<env:Header>
<rm:XYZ_RM>
<rm:Manifest>
<rm:TradeMsg>
<rm:Activity>New</rm:Activity>
<rm:Status>Submit</rm:Status>
<rm:TransType>Trade</rm:TransType>
<rm:ProductType>PTSW</rm:ProductType>
<rm:Submitter>
...................................
................
</fpml:FpML>
</mtc:Trade>
</mtc:XYZ_Catching>
</env:Body>
</env:Envelope>



But I do not want those rm:, mtc:, fpml: prefixes in env header and env body part of xml.
My desire xml is (Partially given, I am fine with envelop part )

<XYZ_RM xmlns="XYZ_RM_9-0">
<Manifest>
<TradeMsg>
<Activity>New</Activity>
<Status>Submit</Status>
<TransType>Block</TransType>
<ProductType>PTSW</ProductType>
.......................................................
...........................
</FpML>
</Trade>
</XYZ_Catching>
</Body>
</Envelope>


How can I remove them using xbean?

I've used the following code but it did not work.

HashMap<String, String> suggestedPrefixes = new HashMap<String, String>();
suggestedPrefixes.put("env", "");
suggestedPrefixes.put("fpml", "");
suggestedPrefixes.put("mtc", "");
suggestedPrefixes.put("rm", "");
suggestedPrefixes.put("http://www.fpml.org/2010/FpML-4-9", "");
suggestedPrefixes.put("XYZ_Catching_9", "");
suggestedPrefixes.put("XYZ_RM_9", "xxxx");
suggestedPrefixes.put("http://schemas.xmlsoap.org/soap/envelope/", "");
XmlOptions opts = new XmlOptions();
opts = opts.setSaveSuggestedPrefixes(suggestedPrefixes);
//opts = opts.setSaveAggressiveNamespaces();
//opts = opts.setCompileSubstituteNames(suggestedPrefixes);
//opts = opts.setUseDefaultNamespace();

String msg = em.xmlText(opts);
message = format(msg);




With regards,
Ritam

Edited by: 808876 on Oct 20, 2011 3:59 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2012
Added on Oct 20 2011
4 comments
3,070 views