Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tXmlMap : use variable in namespace

Hi,

 

Is it possible to have dynamical namespace in tXmlMap componant ? The setAsAnamesapce property seems to always used as s litteral string.

 

 

pat

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

View solution in original post

5 Replies
Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

Thks Sabrina, I will do it. I have applied a work around with a tJava that modify Dom NameSpace before tXmlMapCall
Anonymous
Not applicable
Author

Hi,

Thanks for your feedback. Could you please share your work around tjava on forum?

Best regards

Sabrina

Anonymous
Not applicable
Author

0683p000009Lvb1.png0683p000009Lvby.png

 

 

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;

Anonymous
Not applicable
Author

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. 0683p000009MACn.png 

You can see this solution in the pics below:

0683p000009M4Xg.jpg

Hope I this could help as well!

best regards,
Viktor


ns_trick.jpg