on 07-14-2006 9:05 PM
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.
Accomplished with Java mapping.
Regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
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
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
Here something about DOM:
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/index.html
Regards
Stefan
create it as an attribute and not as element ..that shoul d be fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Hi,
Maybe creating an Attribute with Default values will help?
Havent tried it.. but should help right?
Regards,
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.