on 2014 Apr 29 12:17 PM
Hi Group,
My requirement: Need to change the Namespace tag at the receiver side.
My XML will be something like below:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:ASNList xmlns:ns0="http://www.apriso.com/SXI.GLS">
<EventData>
<SenderName>Test</SenderName>
<ReceiverName>Test</ReceiverName>
<TimeUTC>10:00:00 IST</TimeUTC>
</EventData>
<AdvancedShipmentNotification>
<ID>ASN</ID>
</AdvancedShipmentNotification>
</ns0:ASNList>
I need to transform the message like below;
<?xml version="1.0" encoding="UTF-8"?>
<n1:ASNList xsi:schemaLocation="http://www.apriso.com/PMI.GLS SXI.GLS.ASN.xsd" xmlns:n1="http://www.apriso.com/SXI.GLS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EventData>
<SenderName>LES</SenderName>
<ReceiverName>OSS</ReceiverName>
<EventTimeUTC>2001-12-17T09:30:47.0Z</EventTimeUTC>
</EventData>-
<AdvancedShipmentNotification>
<ID>ASN</ID>
</AdvancedShipmentNotification>
</n1:ASNList>
I have tried to achieve by writing a UDF, all seems to be fine but the "XML is not well-formed". Below is my UDF code:
public String setNSDeclarations(String a,String b,String c,Container container){
StructureNode node = ((StructureNode) container.getParameter("STRUCTURE_NODE"));
node.setNSDeclarations(" xmlns:" + c + "=" + b);
node.setQName(a + "ASNLIST");
return "";
Please suggest if there is any other way to achieve this requirement.
Regards,
Hi Hanumantha,
XMLAnonymizerBean should work for your requirement, please refer the below blog
regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I think you may not be able to generate the target namespace with the help of 'XMLAnonymizerBean '.
Because this bean is mainly used to remove some additional namespaces which are not required.
But in your case , you need to add some more.
You can try to write a java mapping or XSLT to achieve the same. Below is the sample code in java mapping which will generate the namespace in the format you want
Document newdoc = tbuilder.newDocument();
Element root = (Element) newdoc.createElementNS("http://www.apriso.com/SXI.GLS", "n1:ASNList");
root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation","http://www.apriso.com/PMI.GLS SXI.GLS.ASN.xsd");
newdoc.appendChild(root);
Output:
Hi Indrajit,
Yes, It will not be able to handled using 'XMLAnonymizerBean'. So, I thought of going with writing a UDF to generate the namespace tag. I was able to create the XML file but is not properly formatted.
Can anyone suggest if there is any other option to achieve the requirement using Graphical Mapping?
Thanks,
Hi
Modify your UDF code in the below way
use below four input variables
prefix value will be n1
nmspace value will be "http://www.apriso.com/SXI.GLS" (include double quotes )
location value will be xsi:schemaLocation="http://www.apriso.com/PMI.GLS SXI.GLS.ASN.xsd"
value value will be xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
UDF Code:
StructureNode node = ((StructureNode) container.getParameter("STRUCTURE_NODE"));
String finalNamespace = " "+location+ " xmlns:"+prefix + "=" + nmspace+" "+Value;
node.setNSDeclarations(finalNamespace); // notice the space before xmlns:
node.setQName(prefix + ":ASNList");
return"";
A UDF will not help you. I need a Java Mapping as second mapping step. The Java Mapping could add the missing declarations with help of substring method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan,
Sorry for delay in response.
I think we perform the same on UDF to generate the file, it would display differently but when you try to view the source of the file then it should be fine for the customer's system who is picking up the file.
Generally, I feel File adapter will pick up the source of the file. Please correct me.
Regards,
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.