Author |
Message
|
anon_kb |
Posted: Fri Dec 18, 2015 4:12 am Post subject: [HELP] NAMESPACE PROBLEM |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
Hi Guys,
Dont whats the problem with this array. Code seems correct. I tried to get the value of count and it gives me 2. But when it loops it doesnt work. Is there anything wrong with my code? anyway I cant debug on my environment thats why its really hard for me to pinpoint such error. THANKS
Input xml
.
<SQSData>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</SQSDATA>
Expected Output
<Attachment>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</Attachment>
Code: |
DECLARE count INT;
DECLARE lotCount INT;
SET lotCount = CARDINALITY(SQSData.LOT[]);
SET count = 1;
WHILE (count <= lotCount) DO
SET shipmentHeaderOutRef.namespace1:Attachment[count] = SQSData.LOT[count];
SET count = count + 1;
END WHILE; |
Last edited by anon_kb on Mon Dec 21, 2015 10:35 pm; edited 1 time in total |
|
Back to top |
|
 |
timber |
Posted: Fri Dec 18, 2015 5:08 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Don't use CARDINALITY and counted loops. It is much simpler and easier to use a FOR loop.
re: debugging, you simply cannot work without some way of diagnosing errors. Either install the IIB toolkit on your own machine ( and do most of your development work there ), or explain to your manager that you cannot implement message flows 'blind'. |
|
Back to top |
|
 |
anon_kb |
Posted: Fri Dec 18, 2015 5:14 am Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
timber wrote: |
Don't use CARDINALITY and counted loops. It is much simpler and easier to use a FOR loop.
re: debugging, you simply cannot work without some way of diagnosing errors. Either install the IIB toolkit on your own machine ( and do most of your development work there ), or explain to your manager that you cannot implement message flows 'blind'. |
Hi Timber.
All I have to do is copy that repeating fields of LOT to a tag of an outputroot ATTACHMENT . I've already installed IIB and already use it on my previous developments but right now I dont know whats wrong but it gives me an error once I deploy. Cant find the queue. tried to reinstall same problem. Its really hard to work like this.  |
|
Back to top |
|
 |
Vitor |
Posted: Fri Dec 18, 2015 5:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
anon_kb wrote: |
All I have to do is copy that repeating fields of LOT to a tag of an outputroot ATTACHMENT |
And CARDINALITY (as my worthy associate points out) is not the best way of doing that.
anon_kb wrote: |
. I've already installed IIB and already use it on my previous developments but right now I dont know whats wrong but it gives me an error once I deploy. Cant find the queue. tried to reinstall same problem. |
So you've posted the code here because you can't get your code to work & can't get the debugger to work? Do you plan to do this every time you hit a problem because that's going to slow down your development a lot.
There are 2 errors I can see in your code, but given that you've now hosed up your environment so the code doesn't deploy that's probably irrelevant now.
anon_kb wrote: |
Its really hard to work like this.  |
Yes it is. So you should probably stabilize your environment before proceeding. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Dec 18, 2015 5:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
There are no ARRAYs in IIB, or even array structures.
There are ROWs, and sibling nodes.
I'm guessing that you mean "after the flow is deployed and starts processing a message" by "once I deploy".
There is a section in the knowledge center on troubleshooting. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
mgk |
Posted: Fri Dec 18, 2015 6:42 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
As suggested sorting out your environment is a good idea. However, having said that if all you are trying to do is copy whole sections of the message around unchanged then you are making this more complicated that it needs to be. Assuming a valid XML input message (your example is not) then for this message:
Code: |
<SQSData>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</SQSData> |
This code:
Code: |
SET OutputRoot.XMLNSC.ShipmentHeader.Attachment = InputRoot.XMLNSC.SQSData; |
Produces this output message:
Code: |
<ShipmentHeader>
<Attachment>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</Attachment>
</ShipmentHeader> |
You should be able to adapt this to your needs. The reason this works is that IIB will copy whole tree sections and their children automatically.
Kind regards. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
anon_kb |
Posted: Mon Dec 21, 2015 2:57 am Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
mgk wrote: |
As suggested sorting out your environment is a good idea. However, having said that if all you are trying to do is copy whole sections of the message around unchanged then you are making this more complicated that it needs to be. Assuming a valid XML input message (your example is not) then for this message:
Code: |
<SQSData>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</SQSData> |
This code:
Code: |
SET OutputRoot.XMLNSC.ShipmentHeader.Attachment = InputRoot.XMLNSC.SQSData; |
Produces this output message:
Code: |
<ShipmentHeader>
<Attachment>
<LOT>
<LOT_NUMBER>1</LOT_NUMBER>
</LOT>
<LOT>
<LOT_NUMBER>2</LOT_NUMBER>
</LOT>
</Attachment>
</ShipmentHeader> |
You should be able to adapt this to your needs. The reason this works is that IIB will copy whole tree sections and their children automatically.
Kind regards. |
Hi mgk, Actually I already tried this, created another flow and it works but when I insert the modification on the flow. It doesn't work. Thanks for your suggestions guys. I'll request for a stabilize environment on this.
EDIT: I've tried to output the error and here it is.
Error:Element must have a namespace specified if there is a default namespace in scope
Just wondering as what I have said I've created a test flow and test the code and it works but when I transfer the code to the final flow. It gives me this error also on my other elements I've never put a namespace but this one requires it. |
|
Back to top |
|
 |
timber |
Posted: Mon Dec 21, 2015 3:26 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
Error:Element must have a namespace specified if there is a default namespace in scope |
Thanks for quoting the error. The message tree under OutputRoot.XMLNSC contains a default namespace ( probably on the document root tag ). Your ESQL is creating elements with no namespace within the scope of that default namespace. Almost certainly a mistake, which is why XMLNSC flags it up.
The fix is simple; assign the correct namespace to everything that you put in OutputRoot.XMLNSC. That may require you to use a loop instead of mgk's single-line copy. |
|
Back to top |
|
 |
anon_kb |
Posted: Mon Dec 21, 2015 3:41 am Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
timber wrote: |
Quote: |
Error:Element must have a namespace specified if there is a default namespace in scope |
Thanks for quoting the error. The message tree under OutputRoot.XMLNSC contains a default namespace ( probably on the document root tag ). Your ESQL is creating elements with no namespace within the scope of that default namespace. Almost certainly a mistake, which is why XMLNSC flags it up.
The fix is simple; assign the correct namespace to everything that you put in OutputRoot.XMLNSC. That may require you to use a loop instead of mgk's single-line copy. |
Hi Timber, thanks for the answer just wondering I've use same structure as other elements and it runs succefuly but when I map this structure it gives me an error.
EDIT:
I tried to navigate until <LOT_NUMBER>1</LOT_NUMBER> and I get its value. But when I tried to copy the whole tree then it gives me that error |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 21, 2015 4:34 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Let us be clear. There is no default namespace in ESQL. Each element needs to have its namespace set. Hence the reference to a loop by timber.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
timber |
Posted: Mon Dec 21, 2015 8:08 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
just wondering I've use same structure as other elements and it runs succefuly but when I map this structure it gives me an error |
Quote: |
I tried to navigate until <LOT_NUMBER>1</LOT_NUMBER> and I get its value. But when I tried to copy the whole tree then it gives me that error |
You need to understand exactly what is happening in the message flow. When you create the output message tree using ESQL, you are just building a structure in memory. The namespace-related error is happening when the message tree is passed to the output node, and the XMLNSC parser tries to write it as an XML document.
In other words, you now have an output message tree - but it cannot be turned into a valid XML document until you set the correct namespace on every element. |
|
Back to top |
|
 |
anon_kb |
Posted: Mon Dec 21, 2015 9:12 pm Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
timber wrote: |
Quote: |
just wondering I've use same structure as other elements and it runs succefuly but when I map this structure it gives me an error |
Quote: |
I tried to navigate until <LOT_NUMBER>1</LOT_NUMBER> and I get its value. But when I tried to copy the whole tree then it gives me that error |
You need to understand exactly what is happening in the message flow. When you create the output message tree using ESQL, you are just building a structure in memory. The namespace-related error is happening when the message tree is passed to the output node, and the XMLNSC parser tries to write it as an XML document.
In other words, you now have an output message tree - but it cannot be turned into a valid XML document until you set the correct namespace on every element. |
Hi Timber,
I understand your explanation. I'm trying to solve the issue now, anyway heres the full XML and Code
Quote: |
<?xml version="1.0" encoding="UTF-8"?>
<BSMERPShipmentConfirm>
<HEADER>
<Version>2.0</Version>
<DispatchingMode>INTER</DispatchingMode>
</HEADER>
<DETAIL>
<DeliveryNumber>DN1</DeliveryNumber>
<ShipTo>SHIP1</ShipTo>
</DETAIL>
<DETAIL>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP1</ShipTo>
</DETAIL>
<DETAIL>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP1</ShipTo>
</DETAIL>
<DETAIL>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP1</ShipTo>
</DETAIL>
<DETAIL>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP1</ShipTo>
</DETAIL>
<SQSData>
<LOT>
<LotNumber>28501</LotNumber>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP</ShipTo>
<CODNIF> </CODNIF>
<CODNIP> </CODNIP>
<FECFAB>2015-10-12 00:00:00</FECFAB>
</LOT>
<LOT>
<LotNumber>28502</LotNumber>
<DeliveryNumber>MANUAL DISPATCH</DeliveryNumber>
<ShipTo>SHIP</ShipTo>
<CODNIF> </CODNIF>
<CODNIP> </CODNIP>
<FECFAB>2015-10-12 00:00:00</FECFAB>
</LOT>
</SQSData>
<DATABLOCK>
<Pallet>
<LO_HUECO_NUT>
<TIPALM>EX</TIPALM>
<CODALM>PK</CODALM>
<CODHUE>---</CODHUE>
<NRONUT>106010</NRONUT>
</LO_HUECO_NUT>
<LO_NUT>
<NRONUT>106010</NRONUT>
<CODPRO>SBR2382-A-LBNA</CODPRO>
<CODIDO>28501-PG05522-03</CODIDO>
<CANIDO>0.980392</CANIDO>
<FECFAB>2015-10-12 00:00:00</FECFAB>
<FECTEO>2015-10-12 00:00:00</FECTEO>
<ENDFAB>2015-10-12 00:00:00</ENDFAB>
<TICKNR> </TICKNR>
<CONTID> </CONTID>
</LO_NUT>
</Pallet>
</DATABLOCK>
</BSMERPShipmentConfirm>
|
Code: |
CREATE COMPUTE MODULE Sub_PMU_WMB_AGP00_001_MapAGP
-- Declaring name spaces -- START
DECLARE namespace1 NAMESPACE 'http://www.openapplications.org/oagis/9';
DECLARE namespace2 NAMESPACE 'http://www.gic.site.com/oagis/9/site/1';
DECLARE xsi NAMESPACE 'http://www.w3.org/2001/XMLSchema-instance';
-- Declaring name spaces -- END
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
DELETE FIELD OutputRoot.MQRFH2;
DECLARE shipConfirmInRef REFERENCE TO InputRoot.XMLNSC.TSTERPShipmentConfirm;
DECLARE tstSQSData REFERENCE TO shipConfirmInRef.SQSData;
DELETE FIELD OutputRoot.MQRFH2;
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Version = '1.0';
SET OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Encoding = 'UTF-8';
CREATE FIELD OutputRoot.XMLNSC.namespace1:AcknowledgeShipment;
DECLARE ackShipmentOutRef REFERENCE TO OutputRoot.XMLNSC.namespace1:AcknowledgeShipment;
CALL BSMNameSpaceCreations(ackShipmentOutRef);
CALL TEST(tstSQSData, ackShipmentOutRef);
RETURN TRUE;
END;
-- The below procedure maps the Shipment Confirm namespaces.
CREATE PROCEDURE BSMNameSpaceCreations(IN ackShipmentOutRef REFERENCE)
BEGIN
-- Setting the namespaces.
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns:gic = namespace2 ;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns = namespace1;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)releaseID = '9';
END;
CREATE PROCEDURE TEST(IN bsmSQSData REFERENCE, IN ackShipmentOutRef REFERENCE) BEGIN
CREATE FIELD ackShipmentOutRef.namespace1:DataArea.namespace2:Shipment;
DECLARE shipmentOutRef REFERENCE TO ackShipmentOutRef.namespace1:DataArea.namespace2:Shipment;
CREATE FIELD shipmentOutRef.namespace2:ShipmentHeader;
DECLARE shipmentHeaderOutRef REFERENCE TO shipmentOutRef.namespace2:ShipmentHeader;
SET shipmentHeaderOutRef.namespace1:Attachment = tstSQSData;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
CREATE PROCEDURE CopyEntireMessage() BEGIN
SET OutputRoot = InputRoot;
END;
END MODULE;
|
Note: I've created a test mapping just based on the structure on which I got the error. I test it and I got the same error |
|
Back to top |
|
 |
anon_kb |
Posted: Mon Dec 21, 2015 11:39 pm Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
fjb_saper wrote: |
Code: |
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns:gic = namespace2 ;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns = namespace1;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)releaseID = '9';
|
This part of your code is problematic. 'xmlns' is a specific namespace defined in W3... and has nothing in common with namespace1.
Fix your code!  |
Hi FJB,
Thanks for your reply. What do you mean by nothing in common? actually i tried to leave the xmlns blank and it worked but it gives me default namespace (NS1:). I tried to access other elements and it worked except for that SQSData part where I have to copy the whole structure. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 21, 2015 11:52 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
anon_kb wrote: |
fjb_saper wrote: |
Code: |
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns:gic = namespace2 ;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns = namespace1;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)releaseID = '9';
|
This part of your code is problematic. 'xmlns' is a specific namespace defined in W3... and has nothing in common with namespace1.
Fix your code!  |
Hi FJB,
Thanks for your reply. What do you mean by nothing in common? actually i tried to leave the xmlns blank and it worked but it gives me default namespace (NS1:). I tried to access other elements and it worked except for that SQSData part where I have to copy the whole structure. |
Sorry not enough coffee/OJ in the morning... I missed the part where you were obviously trying to declare a default namespace. Just be aware that you still need to assign the namespace to any of the elements.
So the XMLNSC.NameSpaceDecl does not set any namespaces on the document. It only determines what the namespace / prefix will look like on the document (appearance or display of the namespace). If no namespace declaration is done the namespace will follow an autonumbering scheme... In order for any namespace to be assigned to an element in ESQL, including the default one you have to:
- declare it in ESQL (declare xyz namespace '.....'; )
- assign it to the element:
SET ref.namespace:elementname = elementvalue;
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
anon_kb |
Posted: Tue Dec 22, 2015 12:01 am Post subject: |
|
|
Acolyte
Joined: 13 Nov 2014 Posts: 74
|
fjb_saper wrote: |
anon_kb wrote: |
fjb_saper wrote: |
Code: |
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns:gic = namespace2 ;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)xmlns = namespace1;
SET ackShipmentOutRef.(XMLNSC.NamespaceDecl)releaseID = '9';
|
This part of your code is problematic. 'xmlns' is a specific namespace defined in W3... and has nothing in common with namespace1.
Fix your code!  |
Hi FJB,
Thanks for your reply. What do you mean by nothing in common? actually i tried to leave the xmlns blank and it worked but it gives me default namespace (NS1:). I tried to access other elements and it worked except for that SQSData part where I have to copy the whole structure. |
Sorry not enough coffee/OJ in the morning... I missed the part where you were obviously trying to declare a default namespace. Just be aware that you still need to assign the namespace to any of the elements.
So the XMLNSC.NameSpaceDecl does not set any namespaces on the document. It only determines what the namespace / prefix will look like on the document (appearance or display of the namespace). If no namespace declaration is done the namespace will follow an autonumbering scheme... In order for any namespace to be assigned to an element in ESQL, including the default one you have to:
- declare it in ESQL (declare xyz namespace '.....'; )
- assign it to the element:
SET ref.namespace:elementname = elementvalue;
Have fun  |
Hi FJB,
Sorry but I still dont get about this If no namespace declaration is done the namespace will follow an autonumbering scheme
Declare it in esql
1. DECLARE namespace1 NAMESPACE 'http://www.openapplications.org/oagis/9';
DECLARE namespace2 NAMESPACE 'http://www.gic.site.com/oagis/9/site/1';
DECLARE xsi NAMESPACE 'http://www.w3.org/2001/XMLSchema-instance';
2. Assign
SET shipmentHeaderOutRef.namespace1:Attachment = tstSQSData; |
|
Back to top |
|
 |
|