[XML Records] How do I generate the xmlns:xsi parameters with XMLRecords for Progress ERP Service

[XML Records] How do I generate the xmlns:xsi parameters with XMLRecords for Progress ERP Service

  
Forge Component
(23)
Published on 15 Jun by Ricardo Silva
23 votes
Published on 15 Jun by Ricardo Silva
Hi Guys,

I am using the XMLRecords extension to generate the XML that is used as the input to a Progress ERP web service (to check product stocks, update service orders, etc.).

I am able to do everything I need, nevertheless there is one minor detail I am not being able to overcome. Some of the records need to have the property xmlns:xsi. For example: 
<dsInventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

I see that the XMLRecords extension gives me the option of explicitly indicating which is the xmlns property in the RecordXmlConfig options, but I can't seem to figure out how to setup the xmlns:xsi property.

I have even tried to create an attribute in my record with the name Attr_xsi and use the AttributeXmlConfig to rename my Attr_xsi to "xmlns:xsi", nevertheless that results in the error Prefix "xmlns" is reserved for use by XML.

Any ideas?

Kind Regards,

Daniel Lourenço
The current namespace setting in RecordXmlConfig only allows setting the base namespace (xmlns attribute)

Which stack? Java or .Net?
I don't see a reason for that to happen in .net since we use StringBuilders to construct the xml.
In java, since it is a namespace tag, the way to set the attribute is different and cannot be done with the standard "setAttribute"

As a workaround, I'd say the easiest way is to do a Replace right over the generated xml. E.g.
XML = Replace(XML, "<dsInventory ", "<dsInventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance").

Otherwise you'll need to make a small modification to the Extension to (e.g.) detect if the attribute name starts with xmlns: and use the "setAttributeNS" instead of "setAttribute", or add other types of configuration to the RecordXmlConfig. 
If it is java, and you wnat to change the extension :)
On the extension try to do the following on the RecordXmlSerializer.java file:

1. Look for elem.setAttribute(tagName, value); (around line 102)
2. replace it with:

 if(tagName.startsWith("xmlns_")) {  
     elem.setAttributeNS("http://www.w3.org/2000/xmlns/", tagName.replace("_", ":"), value);  
 } else {  
     elem.setAttribute(tagName, value);  
 }

3. Call your attribute (in Studio) "xmlns_xsi" and the extension will detect all xmlns_ and replace it with a proper namespace declaration.

If it works let us know. We can make it have the same behaviour in .Net as well and ask Ricardo Silva to add it to the version in forge (which is in an older version I no longer have)
Thanks for the quick response, Gonçalo!

In fact I am using the .Net stack, so I suppose we either have some validation in the code or we are not just using the StringBuilder to create the XML.

I guess the best thing to do would be to evaluate how the extension should evolve to accommodate also these parameters without the need to manipulate the XML directly.

Thanks again for the answer!

Daniel
Hey guys,

Can you please share an example of creating nested XML?

Thanks a lot.

-- Suraj B