Author |
Message
|
fszostak |
Posted: Tue Feb 15, 2011 9:47 am Post subject: How to remove default namespace NS1 from message |
|
|
Acolyte
Joined: 09 Feb 2011 Posts: 64 Location: Curitiba, Brazil
|
Hi All,
I read a lot of forum topics and articles about this subject, but still could not solve my simple problem.
In my scenary the message is not build in compute node I use Mapping Node, like this:
MQInput -> Mapping -> FileOutput
Transformation occurs perfect, but I need remove NS1: prefix from tags and xmlns="mynamespace" from root tag.
Any idea?
PS: This article is very good to solve the problem for ESQL:http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ac67194_.htm
Thanks!
Szostak _________________ WMB 6.1.005 |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 15, 2011 12:02 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I need remove NS1: prefix from tags and xmlns="mynamespace" from root tag. |
I cannot work out what you need. As always, if you find it difficult to explain the problem then an example is useful. Please post an example of
a) the output you are getting now
and
b) the output you want to get |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Feb 15, 2011 12:41 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
No application that is processing an XML document should have any awareness of the difference between the test element in either of the following two XML snippets.
Code: |
<body xmlns="http://example.com/namespace1">
<test>my fabulous content</test>
</body> |
Code: |
<body xmlns:ns1="http://example.com/namespace1">
<ns1:test>my fabulous content</test>
</body> |
So why do you care which form it is in?
In fact, no application should even care that the namespace prefix is actually the value "ns1" in the second snippet above. It could hold the value "daveisabaddog" and every correctly written application should parse it and access the content without noticing. |
|
Back to top |
|
 |
bsiggers |
Posted: Tue Feb 15, 2011 1:21 pm Post subject: |
|
|
Acolyte
Joined: 09 Dec 2010 Posts: 53 Location: Vancouver, BC
|
From my unfortunate list of bad practices that I've had my experience with, one case that had issues with XML namespaces was a hand-rolled XML parser written entirely in COBOL that didn't like namespaces and empty XML tags... among many, many, many other things - so there were quite some ugly hoops that had to be jumped through, involving string manipulations against the generated XML output.
It used a little state-machine to handle the recursive XML stuff, which was sort of interesting in COBOL. But certainly not recommended or endorsed! |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 15, 2011 2:03 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
one case that had issues with XML namespaces was a hand-rolled XML parser written entirely in COBOL that didn't like namespaces and empty XML tags... among many, many, many other things |
I know this is picky, but it is important. That was not an XML parser - not even close. It was a parser of some arbitrary, non-standard subset of XML.
I'm still waiting for those examples, btw. When I see them, I'll understand what you want to do, and I should be able to help. |
|
Back to top |
|
 |
fszostak |
Posted: Tue Feb 15, 2011 3:10 pm Post subject: |
|
|
Acolyte
Joined: 09 Feb 2011 Posts: 64 Location: Curitiba, Brazil
|
Kimbert,
The message is similar to the posted "mqjeff".
mqjeff,
My process has two steps, both write part of a XML to file. So I have to remove the namespace.
All,
I managed to resolve by removing the reference to the namespace of the XSD file, I needed to create a Message Set project for each XSD file, not a good solution, but it solved my problem.
I'm closing the tight deadline for this job.
Thanks! _________________ WMB 6.1.005 |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Feb 16, 2011 2:40 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
fszostak wrote: |
So I have to remove the namespace. |
Why?
Any application that is requiring that it's input be formatted with a default namespace rather than a namespace prefix is BROKEN.
THAT is what needs fixing, not the messages. |
|
Back to top |
|
 |
mgk |
Posted: Wed Feb 16, 2011 3:05 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
Why?
Any application that is requiring that it's input be formatted with a default namespace rather than a namespace prefix is BROKEN.
THAT is what needs fixing, not the messages. |
I disagree. Sure in an ideal world you would fix the app, but we do not live there . Maybe the app can't be changed or maybe they don't have the time to change it. The whole point of Broker is to connect apps (broken or otherwise) to each other and Broker should make up the difference...
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 |
|
 |
mqjeff |
Posted: Wed Feb 16, 2011 3:16 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
mgk wrote: |
Quote: |
Why?
Any application that is requiring that it's input be formatted with a default namespace rather than a namespace prefix is BROKEN.
THAT is what needs fixing, not the messages. |
I disagree. Sure in an ideal world you would fix the app, but we do not live there . Maybe the app can't be changed or maybe they don't have the time to change it. The whole point of Broker is to connect apps (broken or otherwise) to each other and Broker should make up the difference.. |
Yes, yes. I agree. |
|
Back to top |
|
 |
fszostak |
Posted: Wed Feb 16, 2011 11:38 am Post subject: |
|
|
Acolyte
Joined: 09 Feb 2011 Posts: 64 Location: Curitiba, Brazil
|
mqjeff wrote: |
fszostak wrote: |
So I have to remove the namespace. |
Why?
Any application that is requiring that it's input be formatted with a default namespace rather than a namespace prefix is BROKEN.
THAT is what needs fixing, not the messages. |
This is a long history. You need an external application.
In my opinion, the layout of the external application should be COBOL, but they design a solution using XML. Several companies, which probably keeps your information in the mainframe environment need to send data to this application, but it was designed to receive data in XML format. There may be a matter of design, but is not discussing the case this time.
So I needed to transform a COBOL sequential file in a huge XML. So was born the need to divide the processing of files. It is a special case, is not normally used.
I develop with WMB since version 6.0, a relatively new developer, a question that I see is the very use of the Compute node to create messages, I think particularly the Mapping node a very powerful component and leaves the processing more clear to the developer, I strongly believe in it this component, only use ESQL in the latter case, I do not know if I'm right, but it is my opinion after some time developing.
The flow receives messages, start with the header and then different detail records, the records are read line by line, and the routing is done so that converges to a Mapping node and just after a message is written to file.
Therefore, I need to remove the xmlns attribute and NS1: prefix from the file, because my result would look something like this:
Code: |
<root>
<header xmlns:ns1="http://example.com/namespace1">
<ns1:test>my fabulous content</test>
</header>
<body>
<detail1 xmlns:ns1="http://example.com/namespace1">
<ns1:test>my powerfull content</test>
</detail2>
<detail2 xmlns:ns1="http://example.com/namespace1">
<ns1:test>my great content</test>
</detail2>
.
.
.
</body>
</root>
|
The external application need:
Code: |
<root>
<header>
<test>my fabulous content</test>
</header>
<body>
<detail1>
<test>my powerfull content</test>
</detail2>
<detail1>
<test>my great content</test>
</detail2>
.
.
.
</body>
</root>
|
Regards!
Szostak _________________ WMB 6.1.005
Last edited by fszostak on Wed Feb 16, 2011 1:55 pm; edited 2 times in total |
|
Back to top |
|
 |
Vitor |
Posted: Wed Feb 16, 2011 11:45 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Which ties back to the point kimbert made:
kimbert wrote: |
That was not an XML parser - not even close. It was a parser of some arbitrary, non-standard subset of XML |
The COBOL may claim to be reading XML, but it's not conformant with the W3C specification for XML, but those parts of the specification it's chosen to implement and from a pure XML parsing point of view is broken.
It also ties back to the point mgk made:
mgk wrote: |
The whole point of Broker is to connect apps (broken or otherwise) to each other and Broker should make up the difference |
So everyone's right.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Feb 16, 2011 11:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
So you just need an XML document that has no namespace at all.
That's not the same thing as removing the prefix. The XML document
Code: |
<body>
<test1>my fabulous content</test1>
</body> |
is a different document than
Code: |
<body xmlns:ns1="http://example.com/namespace/">
<ns1:test1>my fabulous content</test1>
</body> |
The easiest way to do this is to create a second message set, that represents the output message you want without the namespaces, and then use mapping to Map By Name to from the XML with namespaces to the XML without namespaces.
There are some other examples floating around the old posts in this forum that will show you ESQL that can go through and do the same thing. |
|
Back to top |
|
 |
fszostak |
Posted: Wed Feb 16, 2011 2:02 pm Post subject: |
|
|
Acolyte
Joined: 09 Feb 2011 Posts: 64 Location: Curitiba, Brazil
|
mqjeff wrote: |
The easiest way to do this is to create a second message set, that represents the output message you want without the namespaces, and then use mapping to Map By Name to from the XML with namespaces to the XML without namespaces. |
Also import the XSD file without namespace to differents message set projects is the best alternative. Duplicate definitions can bring future problems, but it remains a good alternative. i will try this too.
Thank you all for your help.
Szostak. _________________ WMB 6.1.005 |
|
Back to top |
|
 |
Gama |
Posted: Thu Sep 22, 2011 2:15 am Post subject: |
|
|
 Centurion
Joined: 11 Jan 2005 Posts: 103 Location: Portugal
|
Hi,
I had the same problem/situation, ant to solve that i used the node "XLS Transform" whit the follow code.
Code: |
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="text() | processing-instruction() | comment()">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>
|
Regards, |
|
Back to top |
|
 |
|