ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Parsing namespaces with prefix

Post new topic  Reply to topic
 Parsing namespaces with prefix « View previous topic :: View next topic » 
Author Message
souciance
PostPosted: Fri Feb 02, 2018 12:59 am    Post subject: Parsing namespaces with prefix Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

Hello,

Creating namespaces with a prefix for your output is perfectly ok. But how do you parse messages with namespaces that contain a prefix?

Say you have an XML message that starts like this:

Code:
<myXml xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">


There is no schema available either.

How would you declare this in esql to allow the XMLNSC parser to parse the xmlns:s namespace?

Best
Souciance
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Feb 02, 2018 5:38 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Code:
DECLARE s NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';

And the parser is not concerned by the namespace. XMLNS and XMLNSC just handle it.
It is in your SQL that you need to handle the namespace like
Code:
InputRoot.XMLNSC.s:Envelope.myxmlroot;


Hope that helps
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
joebuckeye
PostPosted: Fri Feb 02, 2018 9:15 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 364
Location: Columbus, OH

You don't even need to name the NAMESPACE 's' either, you can call it whatever you want.

The prefix is just a placeholder, the namespace itself is what needs to match between the document and the code.
Back to top
View user's profile Send private message
timber
PostPosted: Fri Feb 02, 2018 9:35 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

The parser *is* concerned with the namespace - but it does not need to be delcared in your XML schema (xsd). The things that most people call "xmlns attributes" are not really attributes at all. They are 'namespace declarations' and they inform the XML parser about how to parse the prefixes on the 'real' tags/attributes.

You do need to ensure that your XML schema is constructed properly. It should declare the tags/attributes in a way that matches the namespaces in the XML document.

All of this is XML 101 really - if you struggle with it then you should stop whatever you are doing and take a couple of online tutorials. Otherwise you're going to make some horrible mistakes.
Back to top
View user's profile Send private message
souciance
PostPosted: Sat Feb 03, 2018 5:55 am    Post subject: Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

timber wrote:
The parser *is* concerned with the namespace - but it does not need to be delcared in your XML schema (xsd). The things that most people call "xmlns attributes" are not really attributes at all. They are 'namespace declarations' and they inform the XML parser about how to parse the prefixes on the 'real' tags/attributes.

You do need to ensure that your XML schema is constructed properly. It should declare the tags/attributes in a way that matches the namespaces in the XML document.

All of this is XML 101 really - if you struggle with it then you should stop whatever you are doing and take a couple of online tutorials. Otherwise you're going to make some horrible mistakes.


Yes it is XML 101 but when the XMLNSC does not refer to the field when the prefix is present but does refer to field when the prefix is not present then obviously there is a need to ask what is going on here. The documentation is not clear on this either.
Back to top
View user's profile Send private message
souciance
PostPosted: Sat Feb 03, 2018 5:58 am    Post subject: Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

fjb_saper wrote:
Code:
DECLARE s NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';

And the parser is not concerned by the namespace. XMLNS and XMLNSC just handle it.
It is in your SQL that you need to handle the namespace like
Code:
InputRoot.XMLNSC.s:Envelope.myxmlroot;


Hope that helps


I don't have the project in front me of me but I am almost sure this was tried by my colleague and the parser did not refer to the field when the prefix was present in the input message but did so when the prefix was removed. I will double check on Monday.
Back to top
View user's profile Send private message
timber
PostPosted: Sun Feb 04, 2018 1:51 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Your question was:
Quote:
How would you declare this in esql to allow the XMLNSC parser to parse the xmlns:s namespace?

...but it sounds as if your actual problem is how to write ESQL to address some part of the XML document. I suspect that this is a simple case of 'getting it wrong' on the part of the developer. It all works very nicely for most people.
Back to top
View user's profile Send private message
souciance
PostPosted: Mon Feb 05, 2018 2:24 am    Post subject: Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

This is the request message from the system. Leave the comments about the crappy message. Already have had those discussions.
Code:

<SOAP_Domain_Msg xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <Context operation="printLabel" operationType="REQUEST_RESPONSE" portType="SCALabelPrintService" portTypeNamespace="http://tempuri.org" port="BasicHttpBinding_SCALabelPrintService" service="RoutingService" serviceNamespace="http://tempuri.org/" fileName="RemoteFiles/xppservice_s.wsdl">
        <SOAP_Version>1.1</SOAP_Version>
        <Namespace xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
    </Context>
    <Header/>
    <Body>
        <SCALabelPrintServicePrintLabelResponse xmlns="http://tempuri.org">
            <response>Blablalablba</response>
        </SCALabelPrintServicePrintLabelResponse>
    </Body>
</SOAP_Domain_Msg>


This line of esql works.
Code:
SET OutputRoot.XMLNSC.PrintedLabels.ApplicationArea.Response = InputRoot.XMLNSC.SOAP_Domain_Msg.Body.tem:SCALabelPrintServicePrintLabelResponse.tem:response;


where "tem" is declared to refer to the tempuri namespace. If we don't refer to the "tem" namespace it won't work. So the XMLNSC parser does indeed seem to require knowledge of the namespace in this case.
Back to top
View user's profile Send private message
abhi_thri
PostPosted: Mon Feb 05, 2018 2:44 am    Post subject: Reply with quote

Knight

Joined: 17 Jul 2017
Posts: 516
Location: UK

It is possible to wildcard the namespace while accessing elements but generally it is good practice to declare it.

Quote:
SET OutputRoot.XMLNSC.PrintedLabels.ApplicationArea.Response = InputRoot.XMLNSC.SOAP_Domain_Msg.Body.*:SCALabelPrintServicePrintLabelResponse.*:response;
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Feb 05, 2018 6:09 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

souciance wrote:
If we don't refer to the "tem" namespace it won't work. So the XMLNSC parser does indeed seem to require knowledge of the namespace in this case.


Yes - you were clearly asleep during the 2nd half of XML 101.

An XML element defined as foo:bar is an element with a name of bar in the namespace of foo. This is entirely separate to an element called bar which is either not part of a namespace or is in the default namespace for the XML document (unless the default namespace is "foo").

So if you try to refer to an element as "bar" when it's "bar" in the namespace of "foo", it doesn't work. In your example, "tem:response" is not the same as "response".
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
joebuckeye
PostPosted: Mon Feb 05, 2018 6:13 am    Post subject: Reply with quote

Partisan

Joined: 24 Aug 2007
Posts: 364
Location: Columbus, OH

souciance wrote:
This is the request message from the system. Leave the comments about the crappy message. Already have had those discussions.


Good, because that is one ugly message.

souciance wrote:

Code:

<SOAP_Domain_Msg xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <Context operation="printLabel" operationType="REQUEST_RESPONSE" portType="SCALabelPrintService" portTypeNamespace="http://tempuri.org" port="BasicHttpBinding_SCALabelPrintService" service="RoutingService" serviceNamespace="http://tempuri.org/" fileName="RemoteFiles/xppservice_s.wsdl">
        <SOAP_Version>1.1</SOAP_Version>
        <Namespace xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"/>
    </Context>
    <Header/>
    <Body>
        <SCALabelPrintServicePrintLabelResponse xmlns="http://tempuri.org">
            <response>Blablalablba</response>
        </SCALabelPrintServicePrintLabelResponse>
    </Body>
</SOAP_Domain_Msg>


This line of esql works.
Code:
SET OutputRoot.XMLNSC.PrintedLabels.ApplicationArea.Response = InputRoot.XMLNSC.SOAP_Domain_Msg.Body.tem:SCALabelPrintServicePrintLabelResponse.tem:response;


where "tem" is declared to refer to the tempuri namespace. If we don't refer to the "tem" namespace it won't work. So the XMLNSC parser does indeed seem to require knowledge of the namespace in this case.


This is working exactly as designed and expected.

There is nothing using the 's' namespace as no fields are using that prefix so that namespace definition can be thrown away.

The SCALabelPrintServicePrintLabelResponse field however is using a default namespace definition (ie no prefix) but that field and all its child fields will be part of that namespace unless a different one is assigned to them.

Now, while the document may not have a prefix since it is using the default namespace, those fields in your code still need to be referred to using the namespace that has been assigned to them (ie the default, no prefix, one).

So your code has to define the tem namespace and use it exactly like your working code does.

Don't mistake the lack of a prefix for the lack of a namespace on a field.
Back to top
View user's profile Send private message
souciance
PostPosted: Mon Feb 05, 2018 11:40 am    Post subject: Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

Thanks for the explanation. Yeah makes sense.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Parsing namespaces with prefix
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.