on 05-21-2012 3:51 AM
Hi All,
I have a requirement where my input message should be mapped to one field in the target structure and the condition here is the namespace element should not be used.
So my first part in the requirement can be achieved by using "return as xml" in the context change. But i am stuck in my second step where i need to remove the namespace.
The output from the source node will be in the xml string and i have tried with replacestring text function but it is throwing error.
Can you please suggest if i can achieve this through standard functions/UDF in the message mapping or i should only go by java mapping?
Thanks,
Prasanthi
Hi,
it depends on which namespace you're trying to remove
a) if this is a main namespace them you can remove it with a substring/replace string
- you just need to escape the quotes
b) if you have filed level namespace them it's best to do it using a java mapping
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
I am trying to remove the main namespace only.
My input xml message structure is something like this:
<ns0:Maintag xmlns:ns2="http://abc.com/pi/XYZ-System/DEF1">
<Field></Field>
<Field1></Field1>
.
.
.
</ns0:Maintag>
And expected output after return xml to target field is:
<Maintag>
<Field></Field>
<Field1></Field1>
.
.
.
</Maintag>
So in my mapping i am using something like:
Maintag-->(return as xml) --> replacestring --> replacestring --> output field
Can you please guide me how shud i pass the values in:
my second parameter of first replace string : ???
third input paramter of first replacestring function: ??
Second input parameter of second replacestring fuction: ???
third parametervalue of second replacestring: ???
Thanks,
Prasanthi
Hi,
there is even a simpler way - try the XSLT from this page:
http://stackoverflow.com/questions/4661154/how-do-i-remove-namespaces-from-xml-using-java-dom
copy&paste from the mentioned page:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<!-- Here! -->
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
set it before your message mapping in the operation mapping and let me know if this works,
Regards,
Michal Krawczyk
Hi Mike,
I just defined the below piece of code in the UDF and it is working as expected.
public static String removeXmlStringNamespaceAndPreamble(String xmlString) {
return xmlString.replaceAll("(<\\?[^<]*\\?>)?", ""). /* remove preamble */
replaceAll("xmlns.*?(\"|\').*?(\"|\')", "") /* remove xmlns declaration */
.replaceAll("(<)(\\w+:)(.*?>)", "$1$3") /* remove opening tag prefix */
.replaceAll("(</)(\\w+:)(.*?>)", "$1$3"); /* remove closing tags prefix */
}
I will also try the xslt way and let you know.
Thanks,
Prasanthi
Hi,
U can still use replace string function...try this:
my second parameter of first replace string :<?xml version="1.0" encoding="UTF-8"?>
third input paramter of first replacestring function: Constant ( ) -keep it as blank
Second input parameter of second replacestring fuction:
xmlns:ns2="http://abc.com/pi/XYZ-System/DEF1"
third parametervalue of second replacestring:Constant ( ) -keep it as blank
Thanks
Amit Srivastava
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.