[XML Records] fixed namespace and prefix issue in xml records java code

[XML Records] fixed namespace and prefix issue in xml records java code

  
Forge Component
(23)
Published on 15 Jun by Ricardo Silva
23 votes
Published on 15 Jun by Ricardo Silva
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.

Thanks,
Thiru
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,
Thiru
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.

Thanks,
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.
<TestEnvelope>
<Header xmlns="http://test.com/envelope/">
<Username xmlns="http://test.com/header/">user</Username>
<password xmlns="http://test.com/header/">pass</password>
</Header>
<Body xmlns="http://test.com/envelope/">
<Attr1 xmlns="http://test.com/body/">attr1</Attr1>
<TestAttr xmlns="http://test.com/body/">
<Attribute1 xmlns="http://test.com/test/">tattq1</Attribute1>
</TestAttr>
</Body>
</TestEnvelope>
 
Modified: This is adding the right namespace along with the prefix to the elements. Please verify output below.
<ns0:Envelope xmlns:ns0="http://test.com/envelope/">
<ns1:Header xmlns:ns1="http://test.com/header/">
<ns1:Username>user</ns1:Username>
<ns1:password>pass</ns1:password>
</ns1:Header>
<ns2:Body xmlns:ns2="http://test.com/body/">
<ns2:Attr1>attr1</ns2:Attr1>
<ns3:TestAttr xmlns:ns3="http://test.com/test/">
<ns3:Attribute1>tattq1</ns3:Attribute1>
</ns3:TestAttr>
</ns2:Body>
</ns0:Envelope>
 
You can switch off the namespace by sending parameter isNamespaceaware as false. The modified code generates XML without namespace. Below is the test output.
<Envelope>
<Header>
<Username>user</Username>
<password>pass</password>
</Header>
<Body>
<Attr1>attr1</Attr1>
<TestAttr>
<Attribute1>tattq1</Attribute1>
</TestAttr>
</Body>
</Envelope>
 
 
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.
 
Thanks,
Thiru
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";
attr.ssSTAttributeXmlConfig.ssName="Attribute1";




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 ="http://test.com/envelope/";
 
RCRecordXmlConfigRecord xmlconfig2 = new RCRecordXmlConfigRecord();
xmlconfig2.ssSTRecordXmlConfig.ssRecordName = "TestHeader";
xmlconfig2.ssSTRecordXmlConfig.ssEffectiveName = "Header";
xmlconfig2.ssSTRecordXmlConfig.ssNamespace ="http://test.com/header/";
 
 
RCRecordXmlConfigRecord xmlconfig4 = new RCRecordXmlConfigRecord();
xmlconfig4.ssSTRecordXmlConfig.ssRecordName = "TestBody";
xmlconfig4.ssSTRecordXmlConfig.ssEffectiveName = "Body";
xmlconfig4.ssSTRecordXmlConfig.ssNamespace ="http://test.com/body/";
 
 
RCAttributeXmlConfigRecord attr = new RCAttributeXmlConfigRecord();
attr.ssSTAttributeXmlConfig.ssAttributeName = "_attr1";
attr.ssSTAttributeXmlConfig.ssName="Attribute1";
 
RLAttributeXmlConfigRecordList rlattr = new RLAttributeXmlConfigRecordList();
rlattr.append(attr);
 
 
 
RCRecordXmlConfigRecord xmlconfig5 = new RCRecordXmlConfigRecord();
xmlconfig5.ssSTRecordXmlConfig.ssRecordName = "Test";
xmlconfig5.ssSTRecordXmlConfig.ssEffectiveName = "Test";
xmlconfig5.ssSTRecordXmlConfig.ssNamespace ="http://test.com/test/";
xmlconfig5.ssSTRecordXmlConfig.ssAttributesConfig = rlattr;
 
RLRecordXmlConfigRecordList xmlconfiglist= new RLRecordXmlConfigRecordList();
xmlconfiglist.append(xmlconfig);
xmlconfiglist.append(xmlconfig2);
xmlconfiglist.append(xmlconfig4);
xmlconfiglist.append(xmlconfig5);
 
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);
}

Thanks
Thiru

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

Thanks,
Thiru
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.

Thanks,
Thiru
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.

Thanks,
Thiru