on 07-22-2014 3:00 PM
Hi Gurus,
I have an importstructure which can be enhanced dynamiccaly hence not all fields are defined and available in the mapping. Now there is a field which is not defined in the importstructure that contains a value I want to read.
I'm trying to create an UDF which reads a value from a structure dynamically. The path of this field is given as an inputparameter (KVK).
public String Bepaal(Container container) throws StreamTransformationException{
Document doc = null;
String value = null;
try {
String inParam = container.getInputParameters().getString("KVK");
//Bouw document op o.b.v. intpustream
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(<How do I get the inputstream??>);
//Bouw xpath expressie t.b.v. het ophalen van de base64 gecodeerde waarde
XPathFactory xFactory = XPathFactory.newInstance();
XPath xpathExpr = xFactory.newXPath();
XPathExpression expr = xpathExpr.compile(inParam);
Object result = expr.evaluate(doc, XPathConstants.NODESET);
//Bepaal gevonden node(s) en bepaal de waarde van de eerstgevonden waarde in de lijst
NodeList nlList = (NodeList) result;
value = nlList.item(0).getNodeValue();
}
catch (Exception e) {
container.getTrace().addWarning(e.toString());
return "";
}
return value;
}
return value
;
The problem is, how do I get the inputstream? I only have a container element.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, this is somewhat helpfull but the field I need is a but more difficult to find, it is not unique.
I need the value in field IdValue where idOwner = "KvK".
Is this possible?
<AdditionalData>
<StaffingAdditionalData>
<CustomerReportingRequirements>
<PurchaseOrderNumber>4357435</PurchaseOrderNumber>
<CustomerReferenceNumber>43545453443</CustomerReferenceNumber>
<PurchaseOrderLineItem>00001</PurchaseOrderLineItem>
</CustomerReportingRequirements>
<ReferenceInformation>
<OrderId idOwner="StaffingCustomer">
<IdValue>546576653</IdValue>
</OrderId>
<StaffingSupplierId idOwner="StaffingCustomer">
<IdValue>346554</IdValue>
</StaffingSupplierId>
<StaffingSupplierId idOwner="KvK">
<IdValue>547365737635</IdValue>
</StaffingSupplierId>
<StaffingCustomerId idOwner="StaffingCustomer">
<IdValue>FC70</IdValue>
</StaffingCustomerId>
<StaffingCustomerId idOwner="OIN">
<IdValue>57645654646</IdValue>
</StaffingCustomerId>
</ReferenceInformation>
</StaffingAdditionalData>
</AdditionalData>
May be you can repeat the same UDF?
for the first one
int i=s.indexOf("<StaffingSupplierId idOwner=\"kvk\">"),j=s.indexOf("</StaffingSupplierId>");
s=s.substring(i+"<StaffingSupplierId idOwner=\"kvk\">".length(),j);
for the second one :
int i=s.indexOf("<IdValue>"),j=s.indexOf("</IdValue>");
s=s.substring(i+"<IdValue>".length(),j);
To make it generic, you can make use of the below UDF:
S -> return as xml
a-> starting tag i.e. <StaffingSupplierId idOwner="kvk">,<IdValue>
b->ending tag i.e. </StaffingSupplierId>, </IdValue>
try
{
int i=s.indexOf(a),j=s.indexOf(b);
if (i>0)
{
s=s.substring(i+a.length(),j);
}
else{
s="";
}
}
catch(Exception e)
{
e.printStackTrace();
}
return s;
Mapping:
Input field -> UDF(StaffingSupplierId )-> UDF(IdValue)->target field.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.