Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

XML Transformation : xmlns attribute

Former Member

Hi experts,

I'm using Simple Transformations to create XML files and it works quite well.

I have a new requirement :

I need to add these attributes to the root element of my file :

xmlns

xmlns:tns1

xmlns:xsi

xsi:schemaLocation

The output xml file should look like this (I show only the root element) :

<ROOT_ELEMENT xmlns="value"

xmlns:tns1="value" xmlns:xsi="value" xsi:schemaLocation="value">

So I added this to my transformation code :

  <tt:attribute name="xmlns" value-ref="variable_containing_value"/>

  <tt:attribute name="xmlns:xsi" value-ref="variable_containing_value"/>

  <tt:attribute name="xmlns:tns1" value-ref="variable_containing_value"/>

  <tt:attribute name="xsi:schemaLocation" value-ref="variable_containing_value"/>

My problem is that the transformation do not activate and I get the folowing syntax error for each attribute containing two parts (ie. part1:part2 , the attribute named "xmlns" works perfectly) :

               undeclared namespace prefix 'xmlns'       

I don't understand why..

Can somebody help please ?

Thanks in advance,

Best regards,

--YC.

1 ACCEPTED SOLUTION

rene_libbert
Explorer

Hi Yohann,

that works fine for your root element, because you define that all Elements has to use this namespace behind xmlns=

With

<tt:attribute name="xmlns:tns1" ...

you set a attribute with Name tns1 wich use the Namespace wich is defined for the namespaceprefix xmlns


Solution:

Within your

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" ... >

you should define your namespace like this:

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"

                   xmlns:yourprefix="yournamespace" >

and then use this prefix like:

<tt:attribute name="yourprefix:tns1" value-ref="variable_containing_value"/>


Greetings René

3 REPLIES 3

rene_libbert
Explorer

Hi Yohann,

that works fine for your root element, because you define that all Elements has to use this namespace behind xmlns=

With

<tt:attribute name="xmlns:tns1" ...

you set a attribute with Name tns1 wich use the Namespace wich is defined for the namespaceprefix xmlns


Solution:

Within your

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" ... >

you should define your namespace like this:

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"

                   xmlns:yourprefix="yournamespace" >

and then use this prefix like:

<tt:attribute name="yourprefix:tns1" value-ref="variable_containing_value"/>


Greetings René

0 Kudos

Hi René !

Thank you for your answer !

It helped but I'm not getting what I expect (yet )

As I'm generating XML files, namespaces are contained into 'variable_containing_value' in my example.

So, in your solution, "yournamespace" is not known as I'm writting the STRANS code.

Using your advice I get no error but the attibute name written in the xml file is :

tns1:tns1

however, I need xmlns:tns1

maybe I'm not familiar enough with xml rules...

Thank you for your help.

Regards,

--YC


0 Kudos

Hello Yohann,

 

I do not know how to implement this with the transformations.

 

You could use a fixed dummy namespace in the the transformation and change it later with ABAP tools. Either with simple strings operations or with the help of iXML libary. I've never tried this, but maybe IF_IXML_NAMESPACE_CONTEXT could help.

 

With CL_UXS_XML_SERVICES=>STRING_TO_DOM you get an instance of iXML document  from your XML String. Using the method IF_IXML_DOCUMENT of the class GET_NAMESPACE_CONTEXT  you receive the above mentioned namespace tools.

Greetings Re