Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
Is it possible to have dynamical namespace in tXmlMap componant ? The setAsAnamesapce property seems to always used as s litteral string.
pat
Hi,
Please feel free to create a new feature jira issue on talend bug tracker.
https://jira.talendforge.org/secure/Dashboard.jspa
Best regards
Sabrina
Hi,
Please feel free to create a new feature jira issue on talend bug tracker.
https://jira.talendforge.org/secure/Dashboard.jspa
Best regards
Sabrina
Hi,
Thanks for your feedback. Could you please share your work around tjava on forum?
Best regards
Sabrina
WS mapping in TXmlMap6 is done without specify nameSpaces, nameSpaces are set by prepareInsertion.
prepareInsertion : set nodes NameSpace with two NameSpaces stored in variables : context.productDelayServicesSONS and context.productDelayServiceBPMLeadtimefileNS
-----------------------
org.dom4j.Document document = ((routines.system.Document)input_row.payload).getDocument();
org.dom4j.Element root = document.getRootElement();
// treat context node
org.dom4j.Element elementContext = root.element("context");
elementContext.add(new org.dom4j.Namespace(null, context.productDelayServicesSONS));
// treat domainObject node
elementContext = root.element("domainObject");
elementContext.add(new org.dom4j.Namespace(null, context.productDelayServiceBPMLeadtimefileNS));
output_row.payload = input_row.payload;
alignResponse :clear WS response namespaces to treat them in new WS call
--------------------
org.dom4j.Document document2 = ((routines.system.Document)input_row.payload).getDocument();
org.dom4j.Element root2 = document2.getRootElement();
org.dom4j.Namespace ns = root2.getNamespace();
List<org.dom4j.Element> elementLst = root2.elements();
for (int i=0,l=elementLst.size();i<l;i++)
{
elementLst.get(i).setQName(new org.dom4j.QName(elementLst.get(i).getName(), org.dom4j.Namespace.NO_NAMESPACE, elementLst.get(i).getQualifiedName()));
elementLst.get(i).setQName(org.dom4j.QName.get(elementLst.get(i).getName(), (String)null, (String)null));
ns = elementLst.get(i).getNamespaceForPrefix("tns");
List<org.dom4j.Element> elementLst2 = elementLst.get(i).elements();
if (elementLst2!=null)
{
for (int j=0,k=elementLst2.size();j<k;j++)
{
elementLst2.get(j).setQName(new org.dom4j.QName(elementLst2.get(j).getName(), org.dom4j.Namespace.NO_NAMESPACE, elementLst2.get(j).getQualifiedName()));
elementLst2.get(j).setQName(org.dom4j.QName.get(elementLst2.get(j).getName(), (String)null, (String)null));
}
}
}
output_row.payload = input_row.payload;
You don't need step through the whole DOM tree to define the namespace. You can use some java syntax trick to do is easier.
1. setup the used values in context variable
2. in the tXMLMAP: click "Change namespace" to namespace you want to change and use this syntax:
" + <insert the context variable here> + "
The thing behind this solution is: Namespace value is a string in the hidden part.You can see similar syntax in your code like below:
// this is the original use
root.addNamespace("tns1", TalendString.replaceSpecialCharForXML("talend/service/TEST/MasterObjects/"));
// this is the trickier use
root.addNamespace("tns2", TalendString.replaceSpecialCharForXML(""+context.connection_TEST_field1_value+""));
So, with the starting and ending quotation marks we are creating two empty string. With the two '+' symbol we concatonate the context variable value with the two empty string. The result is a string value from context variable.
You can see this solution in the pics below:
Hope I this could help as well!
best regards,
Viktor