[XML Records] fixed namespace and prefix issue in xml records java code
Forge component by Afonso Carvalho
Hi Ricardo,
I have made code changes to the xml records. PFA xml records which has fixes for namespace and prefix and now the xml records has isNamespaceAware attribute for the public actions.

Code changes: 
Java file: ActRecordListToXml method: mosRecordListToXml
added new boolean  attribute "inParamIsNamespaceAware" 

Java file: RecordXmlSerializer methods: Serialize, process
Both the methods have code changes and all the changes are commented starting with my name //Thiru

java file: ActRecordToXml method: mosRecordToXml
added new boolean  attribute "inParamIsNamespaceAware" 

java file: ActXmlToRecordList method: mosXmlToRecordList
added new boolean  attribute "inParamIsNamespaceAware" 

java file: RecordXmlDeserializer method: Deserialize, loadRecord
Both the methods have code changes and all the changes are commented starting with my name //Thiru

I have only fixed the compilation errors in .net as i dont have knowledge on .net code.

Please let me know if you still need any more details in understanding the code.

I am also planning to fix the xml date format with timezone and nullValues method for all type of data types instead of only string type.


Ricardo Silva
Hello Thirupathi,

Thanks for this contribution. I'll take a look at it and understand exactly what it does.

I might redesign the way the parameter is passed (instead of adding a parameter, place it in the configuration structure) and I will try to port this to .NET. Not sure when I'll have the time to pick this all up, though.

Can you give us a high level overview of what this does? For example, give us an example XML output / parsed by XML Records with this feature and how it looked without your changes? It might be better to understand what this does than looking at the code.
Thanks Ricardo, ya sure, will set up sample request with and without the changes and send you. This may need sometime, probably early next week.

Thanks again,
Hey guys,

Is this the new feature you are adding to current XML records extension? With this new fix will we be able to add "_" as a prefix when converting Recordlistvalue into XML document? (i.e. for naming attributes like this

<root _att1=value,_att2=value />

Currently we have to write code to prefix "_" before attribute name.

Suraj Borade

Hi Ricardo,
Please find attached zip containing original and modified extensions. I have added main methods in RecordToXML and XMLToRecordList java files. You can run more tests and check.
I am adding the tested output below for original and modified.
Original: This was trying to add namespace of parent to child and not adding namespace to parent. if you check the output of below, envelope namespace is added to childs of envelope but not to the envelope element. Also, both the children of envelope has different namespace but that is gone.
<Header xmlns="https://test.com/envelope/">
<Username xmlns="https://test.com/header/">user</Username>
<password xmlns="https://test.com/header/">pass</password>
<Body xmlns="https://test.com/envelope/">
<Attr1 xmlns="https://test.com/body/">attr1</Attr1>
<TestAttr xmlns="https://test.com/body/">
<Attribute1 xmlns="https://test.com/test/">tattq1</Attribute1>
Modified: This is adding the right namespace along with the prefix to the elements. Please verify output below.
<ns0:Envelope xmlns:ns0="https://test.com/envelope/">
<ns1:Header xmlns:ns1="https://test.com/header/">
<ns2:Body xmlns:ns2="https://test.com/body/">
<ns3:TestAttr xmlns:ns3="https://test.com/test/">
You can switch off the namespace by sending parameter isNamespaceaware as false. The modified code generates XML without namespace. Below is the test output.
Along with the above fix, i have added few more xml timeformats with timezone in TypeMapper.java file and added 
new method called getAttributeNamespace() in XMLSerializerAttributeConfig.java file. 
Please let me know if you still need any more information.

Hi Suraj,
I have tested it and it seems working with the existing forge component only. Here is the output
<Envelope><Header><Username>user</Username><password>pass</password></Header><Body><Attr1>attr1</Attr1><TestAttr _attr1="tattq1"/></Body></Envelope>

Below is the main method code, you can download the above post code and try it.
main configuration is below 2 lines
RCAttributeXmlConfigRecord attr = new RCAttributeXmlConfigRecord();
attr.ssSTAttributeXmlConfig.ssAttributeName = "_attr1";

main method:
public static void main(String[] args) throws Exception {
RCDefaultXmlConfigRecord defaultConfig = new RCDefaultXmlConfigRecord() {
ssSTDefaultXmlConfig.ssExcludeIfNull = true;
ssSTDefaultXmlConfig.ssXmlDeclaration.ssSTXmlDeclaration.ssAddDeclaration = false;
ssSTDefaultXmlConfig.ssRecordListMode = "S";
ssSTDefaultXmlConfig.ssAttributePrefix = "Attrib";
RCRecordXmlConfigRecord xmlconfig = new RCRecordXmlConfigRecord();
xmlconfig.ssSTRecordXmlConfig.ssRecordName = "TestEnvelope";
xmlconfig.ssSTRecordXmlConfig.ssEffectiveName = "Envelope";
xmlconfig.ssSTRecordXmlConfig.ssNamespace ="https://test.com/envelope/";
RCRecordXmlConfigRecord xmlconfig2 = new RCRecordXmlConfigRecord();
xmlconfig2.ssSTRecordXmlConfig.ssRecordName = "TestHeader";
xmlconfig2.ssSTRecordXmlConfig.ssEffectiveName = "Header";
xmlconfig2.ssSTRecordXmlConfig.ssNamespace ="https://test.com/header/";
RCRecordXmlConfigRecord xmlconfig4 = new RCRecordXmlConfigRecord();
xmlconfig4.ssSTRecordXmlConfig.ssRecordName = "TestBody";
xmlconfig4.ssSTRecordXmlConfig.ssEffectiveName = "Body";
xmlconfig4.ssSTRecordXmlConfig.ssNamespace ="https://test.com/body/";
RCAttributeXmlConfigRecord attr = new RCAttributeXmlConfigRecord();
attr.ssSTAttributeXmlConfig.ssAttributeName = "_attr1";
RLAttributeXmlConfigRecordList rlattr = new RLAttributeXmlConfigRecordList();
RCRecordXmlConfigRecord xmlconfig5 = new RCRecordXmlConfigRecord();
xmlconfig5.ssSTRecordXmlConfig.ssRecordName = "Test";
xmlconfig5.ssSTRecordXmlConfig.ssEffectiveName = "Test";
xmlconfig5.ssSTRecordXmlConfig.ssNamespace ="https://test.com/test/";
xmlconfig5.ssSTRecordXmlConfig.ssAttributesConfig = rlattr;
RLRecordXmlConfigRecordList xmlconfiglist= new RLRecordXmlConfigRecordList();
RCTestHeaderRecord th = new RCTestHeaderRecord();
th.ssSTTestHeader.ssUsername = "user";
th.ssSTTestHeader.sspassword = "pass";
RCTestRecord tr = new RCTestRecord();
tr.ssSTTest.ssAttribute1 = "tattq1";
RCTestBodyRecord tb = new RCTestBodyRecord();
tb.ssSTTestBody.ssAttr1 = "attr1";
tb.ssSTTestBody.ssTestAttr = tr;
RCTestEnvelopeRecord te = new RCTestEnvelopeRecord();
te.ssSTTestEnvelope.ssBody = tb;
te.ssSTTestEnvelope.ssHeader = th;
System.out.println(ActRecordToXml.mosRecordToXml(te, xmlconfiglist, defaultConfig, false).outParamXml);
System.out.println(ActRecordToXml.mosRecordToXml(te, xmlconfiglist, defaultConfig, false).outParamXml);


Hi Ricardo,
Did you get chance to look at my code?

Ricardo Silva
I'm sorry, but not yet.

This weekend I will also probably not be able to. In any case you've shared the change you made and people who require this funcionality can get it from this thread.
Hi Ricardo,
Happy new year 2016.
Here I am attaching the latest code. waiting for your feedback.


Also, the present extension is working only with Record and not directly with structures. If you give some guidance on how can it be upgraded to use structures directly I would like to work on that as well.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.