Author |
Message
|
schroederms |
Posted: Mon Jun 10, 2013 8:57 am Post subject: Dynamic parsing question |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
I'm trying to parse down to the REQUEST tag section of this XML WITHOUT hard coding the the parent tag name, in this case SAP_DPTBCHUB. This first outer tag will change from message to message. I've tried many things, including referencing it by the .*[nbr] for example, with no luck.
Any help would be appreciated!
thanks.
Code: |
<?xml version="1.0" encoding="utf-8"?>
<SAP_DPTBCHUP xmlns="http://www.Apriso.com/SAP_DPTBCHUP.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SessionContext>
<EmployeeID>100000002</EmployeeID>
<EmployeeNo>darshan</EmployeeNo>
<TransactionTime>2013-06-07T21:12:42.3372294</TransactionTime>
<Facility>ALG1</Facility>
<Department />
<OperationID>100000756</OperationID>
<OperationRevision>DPT.I.1.0</OperationRevision>
<StepSequenceNo>3</StepSequenceNo>
<FunctionName>WriteXML</FunctionName>
<TransactionGUID>T9501</TransactionGUID>
<EquipmentID>0</EquipmentID>
<FunctionID>100010256</FunctionID>
<OperationCode>Upload_BatchCharacteristicUpdate</OperationCode>
<OprSequenceNo />
<LocalTransactionTime>2013-06-07T21:12:45.0091044</LocalTransactionTime>
<PartnerInfo>
<RCVPOR>SAPC64</RCVPOR>
<SNDPRN>FLEXNET</SNDPRN>
<RCVPRN>SAPLOG</RCVPRN>
<RCVPRT>LS</RCVPRT>
<SNDPOR>A000000022</SNDPOR>
<SNDPRT>LS</SNDPRT>
<CLNT>100</CLNT>
</PartnerInfo>
</SessionContext>
[color=red] [b]<REQUEST>[/b][/color]
<DESTINATION>
<INSTANCE>DV3</INSTANCE>
<CLIENT>120</CLIENT>
</DESTINATION>
<APP>
<TYPE>DPTBCHUP</TYPE>
<AUFNR>2</AUFNR>
<CHARG>5042</CHARG>
<CHAR>hte</CHAR>
<NUMERIC>5</NUMERIC>
<ALPHA>gfd</ALPHA>
</APP>
[color=red] [b]</REQUEST>[/b][/color]
</SAP_DPTBCHUP> |
|
|
Back to top |
|
 |
Vitor |
Posted: Mon Jun 10, 2013 9:02 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
I'd expect the [nbr] construction to work. Remember that you may have to cast it:
doesn't exist because REQUEST isn't a child of the XML declaration (the [1] element in the document) but
Code: |
(XMLNSC.Element)[1].REQUEST |
does.
Also be sure to specify either the right namespace or a wildcard _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 10, 2013 9:10 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Code: |
DECLARE myRef reference to InputRoot.XMLNSC.*:*.*:REQUEST; |
|
|
Back to top |
|
 |
schroederms |
Posted: Mon Jun 10, 2013 9:49 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
I tried both or your examples, neither gets me to the tags below REQUEST. In the case of InputRoot.XMLNSC.*:*.*:REQUEST,
I have this coded:
DECLARE myRef reference to InputRoot.XMLNSC.*:*.*:REQUEST;
Set Environment.INSTANCE = myRef.DESTINATION.INSTANCE;
Set Environment.CLIENT = myRef2.DESTINATION.CLIENT;
and both Environments fields are null.
When I parse this message using RFHUtil, it does not look like REQUEST is needed to be parsed with as though there is name spaces??? Here is what I'm seeing using RFHUtil, using PARSED for data format.
Thanks.
SAP_DPTBCHUP
SAP_DPTBCHUP.(XML.attr)xmlns='http://www.Apriso.com/SAP_DPTBCHUP.xsd'
SAP_DPTBCHUP.(XML.attr)xmlns:xsd='http://www.w3.org/2001/XMLSchema'
SAP_DPTBCHUP.SessionContext
SAP_DPTBCHUP.SessionContext.EmployeeID='100000002'
SAP_DPTBCHUP.SessionContext.EmployeeNo='darshan'
SAP_DPTBCHUP.SessionContext.TransactionTime='2013-06-07T21:12:42.3372294'
SAP_DPTBCHUP.SessionContext.Facility='ALG1'
SAP_DPTBCHUP.SessionContext.Department=''
SAP_DPTBCHUP.SessionContext.OperationID='100000756'
SAP_DPTBCHUP.SessionContext.OperationRevision='DPT.I.1.0'
SAP_DPTBCHUP.SessionContext.StepSequenceNo='3'
SAP_DPTBCHUP.SessionContext.FunctionName='WriteXML'
SAP_DPTBCHUP.SessionContext.TransactionGUID='T9501'
SAP_DPTBCHUP.SessionContext.EquipmentID='0'
SAP_DPTBCHUP.SessionContext.FunctionID='100010256'
SAP_DPTBCHUP.SessionContext.OperationCode='Upload_BatchCharacteristicUpdate'
SAP_DPTBCHUP.SessionContext.OprSequenceNo=''
SAP_DPTBCHUP.SessionContext.LocalTransactionTime='2013-06-07T21:12:45.0091044'
SAP_DPTBCHUP.SessionContext.PartnerInfo
SAP_DPTBCHUP.SessionContext.PartnerInfo.RCVPOR='SAPC64'
SAP_DPTBCHUP.SessionContext.PartnerInfo.SNDPRN='FLEXNET'
SAP_DPTBCHUP.SessionContext.PartnerInfo.RCVPRN='SAPLOG'
SAP_DPTBCHUP.SessionContext.PartnerInfo.RCVPRT='LS'
SAP_DPTBCHUP.SessionContext.PartnerInfo.SNDPOR='A000000022'
SAP_DPTBCHUP.SessionContext.PartnerInfo.SNDPRT='LS'
SAP_DPTBCHUP.SessionContext.PartnerInfo.CLNT='100'
SAP_DPTBCHUP.REQUEST
SAP_DPTBCHUP.REQUEST.DESTINATION
SAP_DPTBCHUP.REQUEST.DESTINATION.INSTANCE='DV3'
SAP_DPTBCHUP.REQUEST.DESTINATION.CLIENT='120'
SAP_DPTBCHUP.REQUEST.APP
SAP_DPTBCHUP.REQUEST.APP.TYPE='DPTBCHUP'
SAP_DPTBCHUP.REQUEST.APP.AUFNR='2'
SAP_DPTBCHUP.REQUEST.APP.CHARG='5042'
SAP_DPTBCHUP.REQUEST.APP.CHAR='hte'
SAP_DPTBCHUP.REQUEST.APP.NUMERIC='5'
SAP_DPTBCHUP.REQUEST.APP.ALPHA='gfd' |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Jun 10, 2013 9:59 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Adding Trace nodes will display the Logical Message Tree. From this output, you can write explicit code to get the right values. From the explicit code, you can substitute * in the places where you do not want to reference the field/folder name. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 10, 2013 10:20 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
lancelotlinc wrote: |
Adding Trace nodes will display the Logical Message Tree. From this output, you can write explicit code to get the right values. From the explicit code, you can substitute * in the places where you do not want to reference the field/folder name. |
And where you want to use * in the places you do not want to reference the namespace by name.... |
|
Back to top |
|
 |
schroederms |
Posted: Mon Jun 10, 2013 10:32 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
Ok I'm getting close but not getting what I need. Let me show you what I've done so far:
Declare ns1 namespace 'http://www.Apriso.com/SAP_DPTBCHUP.xsd';
This statment brought back my result...
Set Environment.APP = InputRoot.XMLNSC.ns1:SAP_DPTBCHUP.ns1:REQUEST.ns1:APP.ns1:TYPE;
So then I went one step farther and coded this and this too brought back what I wanted.
Set Environment.APP = InputRoot.XMLNSC.*:SAP_DPTBCHUP.*:REQUEST.*:APP.*:TYPE;
But when I try this below, it brings back a null value:
Set Environment.APP = InputRoot.XMLNSC.*:*.*:REQUEST.*:APP.*:TYPE; |
|
Back to top |
|
 |
rekarm01 |
Posted: Mon Jun 10, 2013 11:52 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
schroederms wrote: |
But when I try this below, it brings back a null value:
Code: |
Set Environment.APP = InputRoot.XMLNSC.*:*.*:REQUEST.*:APP.*:TYPE; |
|
If the Trace node indicates that XMLNSC (for example) has more than one child element, then the ESQL reference may need a suitable type qualifier or subscript to match the correct one. |
|
Back to top |
|
 |
schroederms |
Posted: Mon Jun 10, 2013 12:22 pm Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
Correct, but there is only one outer tag, and when I qualify it, it brings back the expected results.
This is what I see in the trace.
(0x01000000:Folder):XMLNSC = ( ['xmlnsc' : 0x117e72490]
(0x01000400:NamespaceDecl):XmlDeclaration = (
(0x03000100:Attribute):Version = '1.0' (CHARACTER)
(0x03000100:Attribute):Encoding = 'utf-8' (CHARACTER)
)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:SAP_DPTBCHUP = (
(0x03000102:NamespaceDecl):xmlns = 'http://www.Apriso.com/SAP_DPTBCHUP.xsd' (CHA
RACTER)
(0x03000102:NamespaceDecl)http://www.w3.org/2000/xmlns/:xsd = 'http://www.w3.org/2001/XMLSchema' (CHARACTER
)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:SessionContext = (
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:EmployeeID = '100000002' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:EmployeeNo = 'darshan' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:TransactionTime = '2013-06-07T21:12:42.3372294' (CHARACTE
R)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:Facility = 'ALG1' (CHARACTER)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:Department =
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:OperationID = '100000756' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:OperationRevision = 'DPT.I.1.0' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:StepSequenceNo = '3' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:FunctionName = 'WriteXML' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:TransactionGUID = 'T9501' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:EquipmentID = '0' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:FunctionID = '100010256' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:OperationCode = 'Upload_BatchCharacteristicUpdate' (CHA
RACTER)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:OprSequenceNo =
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:LocalTransactionTime = '2013-06-07T21:12:45.0091044' (CHARACTE
R)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:PartnerInfo = (
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:RCVPOR = 'SAPC64' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:SNDPRN = 'FLEXNET' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:RCVPRN = 'SAPLOG' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:RCVPRT = 'LS' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:SNDPOR = 'A000000022' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:SNDPRT = 'LS' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:CLNT = '100' (CHARACTER)
)
)
(0x01000000:Folder )http://www.Apriso.com/SAP_DPTBCHUP.xsd:REQUEST = (
(0x01000000:Folder)http://www.Apriso.com/SAP_DPTBCHUP.xsd:DESTINATION = (
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:INSTANCE = 'DV3' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:CLIENT = '120' (CHARACTER)
)
(0x01000000:Folder)http://www.Apriso.com/SAP_DPTBCHUP.xsd:APP = (
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:TYPE = 'DPTBCHUP' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:AUFNR = '2' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:CHARG = '5042' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:CHAR = 'hte' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:NUMERIC = '5' (CHARACTER)
(0x03000000:PCDataField)http://www.Apriso.com/SAP_DPTBCHUP.xsd:ALPHA = 'gfd' (CHARACTER)
)
)
)
)
) |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 10, 2013 12:40 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The namespace declaration counts.
You want *:*[<] |
|
Back to top |
|
 |
schroederms |
Posted: Mon Jun 10, 2013 12:45 pm Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 10, 2013 12:56 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
As rekarm01 said, you could also use "(XMLNSC.Element)*:*", to indicate you wanted the first anonymous child that is an XMLNSC Element, rather than indicating you wanted the last anonymous child. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jun 11, 2013 3:04 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
The top level of an XML document ( InputRoot.XMLNSC ) can contain
- an optional prolog ( the XML declaration ). This must be first if it exists in the document.
- optional processing instructions/comments
- exactly one root tag
- optional processing instructions/comments
So *:*[<], which takes the last top-level child of XMLNSC, will not be reliable in all cases. It might select a comment or a processing instruction instead of the root tag.
This is exactly why XMLSNC.Element was provided. The safe way to do it is:
Code: |
InputRoot.XMLNSC.(XMLNSC.Element)*:*.*:REQUEST |
|
|
Back to top |
|
 |
schroederms |
Posted: Tue Jun 11, 2013 4:14 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
|
Back to top |
|
 |
schroederms |
Posted: Tue Jun 11, 2013 4:58 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
I appreciate everyone's help, I've got it doing what I need to have it do. Completely namespace independent (multiple namespace possible from a third party company), which I then loop through whatever the tag names are under REQUEST.APP, removing the name space, and building a message to feed into SAP.
Thanks Again!
Set Environment.MyloopStart = Cardinality(InputRoot.XMLNSC.(XMLNSC.Element)*:*.*:REQUEST.*:APP.*:*[]);
--Pull all data under REQUEST.APP and prepare for SAP feed.
While i <= Environment.MyloopStart Do
Set Environment.APP.[i] NAME = Fieldname(InputRoot.XMLNSC.(XMLNSC.Element)*:*.*:REQUEST.*:APP.*:*[i]);
Set Environment.APP.[i] = InputRoot.XMLNSC.(XMLNSC.Element)*:*.*:REQUEST.*:APP.*:*[i];
set i = i +1;
End While;
Set OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Version=InputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Version;
Set OutputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Encoding=InputRoot.XMLNSC.(XMLNSC.XmlDeclaration)*.(XMLNSC.Attribute)Encoding;
--
--
Set OutputRoot.XMLNSC.REQUEST.APP = Environment.APP; |
|
Back to top |
|
 |
|