cancel
Showing results for 
Search instead for 
Did you mean: 

Redefining namespaces

Former Member
0 Kudos

Hi there,

we have a request from a client to redefine the namespace of some elements inside the xml.

For example, the following XML:

<test xmlns="http://test">

<field1/>

<field2/>

<field2/>

</test>

must be sent like:

<test xmlns="http://test">

<field1/>

<field2 xmlns="http://test"/>

<field2 xmlns="http://test"/>

</test>

Is there any way to accomplish this using mapping (java or xslt) or some of the default modules? I'm using Soap receiver adapter.

PS: I've checked out that if I used different prefixes, like:

<test xmlns="http://test">

<field1/>

<ns0:field2 xmlns:ns0="http://test"/>

<ns0:field2 xmlns:ns0="http://test"/>

</test>

then it would be easy, using <xsl:copy-of> function in XSLT mapping. But the client also demands that the output message must have no prefixes (which, btw, I accomplished using XML Anonymizer Module). 😕

Thanks in advance,

Henrique.

Accepted Solutions (0)

Answers (6)

Answers (6)

henrique_pinto
Active Contributor
0 Kudos

Accomplished with Java mapping.

Regards,

Henrique.

stefan_grube
Active Contributor
0 Kudos

If the structure is not too complicated, you can create a data type where you have an element field2 with an attribute xmlns.

In mapping you assign the constant "http://test" to the attribute.

You can do this as well for the root node and when when you delete the name space of the message type, that should make the XML Anonymizer Module needless.

Stefan

henrique_pinto
Active Contributor
0 Kudos

Stephan,

as per the XML Namespaces specification, "xmlns" is not a valid attribute name (it's a reserved name).

Regards,

Henrique.

henrique_pinto
Active Contributor
0 Kudos

Rajeev,

actually the .xsd is not the matter, since it defines correctly the namespace for all the fields (independent of which prefix you use).

The problem is with the client application that consumes that xml file. As they have developed it, they require that:

1. the xml doesnt have any prefixes (accomplished with anonymizer);

2. some of the inside tags have the namespace redeclared (I dont know whys that, and I totally aggree that it's totally not standard-compliant to require that, but they are the bosses );

3. the xml must be encapsulated in another xml as a string (accomplished using XSLT mapping).

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

then see your Client is finally needing this structure:

<test xmlns="http://test">

<field1/>

<field2 xmlns="http://test"/>

<field2 xmlns="http://test"/>

</test>

So what is the problem if you define a target data type for above structure and in field2 node you make an attribute and give its default value as http://test

Thanks,

Rajeev Gupta

Former Member
0 Kudos

Hi Henrique,

for xmlns attribute, in occurance give optional

Then in mapping give the namespace value http://test to this attribute.

Thanks,

Rajeev Gupta

Message was edited by:

RAJEEV GUPTA

henrique_pinto
Active Contributor
0 Kudos

Rajeev, check my answer above to Stephan.

"xmlns" is not a valid attribute name.

Regards,

Henrique.

stefan_grube
Active Contributor
0 Kudos

Sure, the xmlns is an attribute. It is a reserved name for a special attribute.

http://www.w3.org/TR/2006/REC-xml-names11-20060816/

"A namespace (or more precisely, a namespace binding) is declared using a family of reserved <b>attributes</b>. Such an <b>attribute</b>'s name must either be xmlns or begin xmlns:."

Regards

Stefan

henrique_pinto
Active Contributor
0 Kudos

what I wanted to say is that you cant create a xsd defining an attribute of name xmlns (at least in standard-compliant programs). Such an xsd cant be created in XMLSpy, for example.

However, you can create that attribute in a new Data Type in XI (not fully compliant). But the .xsd has some namespace requirements that a new Data Type wouldnt satisfy (I need namespace for the whole message and not only the 1st tag, for example).

Regards,

Henrique.

Former Member
0 Kudos

Hi Henrique,

i agree xmlns is a reserved name.....

but see my above reply again.....i have said create an attribute with xmlns name and in its occurance give optional......

then your data type will be created.....then you can use it in msg mapping.....then in msg mapping, map this xmlns attribute to a constant http://test.

Thanks,

Rajeev Gupta

udo_martens
Active Contributor
0 Kudos

Hi Henrique,

an ABAP mapping can solve your problems very easy:

You dont need any ABAP mapping knowledge, just change to string with function "ECATT_CONV_XSTRING_TO_STRING". Use ABAP string methods, like REPLACE to replace the namespace. Change back the result to Xstring with "ECATT_CONV_STRING_TO_XSTRING".

Regards,

Udo

henrique_pinto
Active Contributor
0 Kudos

Any news on this, using Java or XSLT?

Udo, could you provide some more information on how to accomplish that with ABAP mapping?

Regards,

Henrique.

prabhu_s2
Active Contributor
0 Kudos

yes, we can have it done using java mapping.

henrique_pinto
Active Contributor
0 Kudos

Could you please provide some more info on that?

Regards,

Henrique.

Former Member
0 Kudos

HI,

Yes this is possible with the JAVA SAX parser..

see below links

Regards

Chilla..

<i>Points rewarded if it is usefull..</i>

henrique_pinto
Active Contributor
0 Kudos

Chandra, thanks for the info on Sax parser, but the links didnt seem helpful on that matter.

Could you please provide some more information?

Regards,

Henrique.

prabhu_s2
Active Contributor
0 Kudos

u may need to code and handle this funtionality explicitly....

public void startElement (String namespaceURI, String lName, String qName, Attributes attrs)

throws SAXException {

String eName = lName; // element name

if (eName.equals("test xmlns=http://test”)) {

//Get the tag xmlns=”http://test” and store it in a string variable say MrX.

write("<test xmlns="http://test">");

} else if (eName.equals("field2")) {

//concatenate “< “ +field2 “ “ MrX+”>” into sting variable say MrY

Write(MrY);

} …..

This wud be the part of code in method startElement when u use java mapping

prabhu_s2
Active Contributor
0 Kudos

i got a very gud java mapping tutorial for sax and dom parsers. but it wont provide u the exact piece of code. u may need to build in ur logic with the aid of those.

henrique_pinto
Active Contributor
0 Kudos

Hey Prabhu,

thanks for your help.

Actually I've accomplished something similar on XSLT,using CDATA tags (to handle the namespace declaration as strings).

I was just wondering if there was some standard method in Java for that (something like Node.addNamespace() would be fine ).

Also, I'd like to have those tutorials. Could u send to my email please?

Regards,

Henrique.

stefan_grube
Active Contributor
STALANKI
Active Contributor
0 Kudos

create it as an attribute and not as element ..that shoul d be fine.

henrique_pinto
Active Contributor
0 Kudos

Guys,

the .XSD file is created by the customer and I can't change it.

Any other sugestions?

Former Member
0 Kudos

Hi Henrique,

<i>the .XSD file is created by the customer and I can't change it.</i> - so you mean to say your target struc is give by client and that does not have ns for inner fields in it - correct or not....... but id this is the case why you have said below:

<i>must be sent like:

<test xmlns="http://test">

<field1/>

<field2 xmlns="http://test"/>

<field2 xmlns="http://test"/>

</test></i>

i.e why you need ns for inner fields.

Could you please explain your req in more detail.

Thanks,

Rajeev Gupta

Message was edited by:

RAJEEV GUPTA

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

Maybe creating an Attribute with Default values will help?

Havent tried it.. but should help right?

Regards,

Bhavesh

Former Member
0 Kudos

Hi,

I am not sure if I am answering your query here. But as far as I understood, we can create the namespace with normal graphical mapping.

say the target is

test xmlns="http://test">

<field1/>

<field2 xmlns="http://test"/>

<field2 xmlns="http://test"/>

</test>

we could map the target node <field2> with a constant having a value <field2 xmlns="http://test"/>

Just my point of view.

Regards,

Smitha.