Add dynamic namespace declaration into xml root element

Hello all,
i've have two scenarios (mail to mail and file to file) with the same issue : no namespace in my XML file and i have to create one 'dynamically' from XML values.
Example :
<root>
<name>test</name>
<email>test</email>
<schema>schemaID</schema>
</root>
Now I want to add infos into the root element for namespace declaration and so on, without expansion of the xsd. I've must use the value from the field schemaID.
Example:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns: namespace="http://test.de/schemaID">
<name>test</name>
<email>test</email>
</root>
I've already done it before through XSLT but it wasn't dynamic !! I don't know how to do it in XSL and i am not a java expert.
Someone got an idea ?
Thanks,
Jean-Philippe.

Hi,
  If you want to add name space at mapping level two options
1)Using XSLT Mapping ,its very easy,google it to get sample XSLT code ,it will solve your problem.
2)Using java mapping,in java mapping use regular expression code ,using regex(Regulkar expresion)we can add any content in message at any level.
Regards,
Raj

Similar Messages

  • Add namespace declaration into xml root element

    Hello experts,
    I have the following problem:
    I generate a xml message with the following structure (example):
    How can I realise this requirement?
    Thanks and best regards!
    Christopher Kühn

    Hi Christopher,
    Call the below code as a javamappinf in the operation mapping... So now your operation mapping will have two mappings one to convert source to target XML and second this java mapping which will add namespace to your target xml
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import  com.sap.aii.mapping.api.DynamicConfiguration;
    import com.sap.aii.mapping.api.DynamicConfigurationKey;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    import com.sap.aii.mapping.api.InputHeader;
    public class JavaMapping extends AbstractTransformation {
         public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
         getTrace().addInfo("JAVA Mapping Called");
         //Input payload is obtained by using arg0.getInputPayload().getInputStream()
         String inData = convertStreamToString(arg0.getInputPayload().getInputStream());
         String outData = inData.replaceFirst("<root>", "<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespace=\"http://test.de/test.xsd\">");
         try
         //8. The JAVA mapping output payload is returned using the TransformationOutput class
         // arg1.getOutputPayload().getOutputStream()
              arg1.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
         catch(Exception exception1) { }
         public String convertStreamToString(InputStream in){
         StringBuffer sb = new StringBuffer();
         try
         InputStreamReader isr = new InputStreamReader(in);
         Reader reader =
         new BufferedReader(isr);
         int ch;
         while((ch = in.read()) > -1) {
              sb.append((char)ch);}
              reader.close();
         catch(Exception exception) { }
         return sb.toString();
    check stefans blog on the jar files that you need to make this mapping /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    Regards
    Suraj
    Regards
    Suraj

  • Avoid repeating namespace declaration in xml output

    Hi all,
    I'm trying an IDoc -> XML File (specifically UBL-format) scenario, and it is working fine. But the resulting XML contains repeating namespace declarations for each element, instead of a "common" declaration at the root element.
    How can I avoid this, so the message contains the namespace declarations in root node, and only uses the namespace prefix for each element?
    The target format, external definition, is an XSD with several import statements, and all external references have been set up, meaning all referenced XSD's are imported too, and have the "Source"-field set according to the import statement.
    Sample result file (top of file only):
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:Invoice xmlns:ns0="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <ns2:UBLVersionID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2.0</ns2:UBLVersionID>
    <ns2:CustomizationID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:www.cenbii.eu:transaction:BiiCoreTrdm001:ver1.0:extentionId</ns2:CustomizationID>
    <ns2:ProfileID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:www.cenbii.eu:profile:bii05:ver1.0</ns2:ProfileID>
    <ns2:ID xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">9010045446</ns2:ID>
    <ns2:IssueDate xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2011-04-19</ns2:IssueDate>
    <ns2:InvoiceTypeCode...
    PI version 7.11.
    Thanks for all help.
    Br,
    Kenneth

    Hi Mon,
    You can use below xslt 1.0 mappings.
    The first one will copy all namespaces (declared) to a newly created root element.
    The seconde one will delete the 'old' root element.
    => The result will look like an xml where the namespacesare moved to the root element.
    First xslt:
    <?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" encoding="UTF-8"/>
    <xsl:template match="/">
    <Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ns4="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
    <xsl:copy-of select="." />
    </Invoice>
    </xsl:template>
    </xsl:stylesheet>
    Second xslt:
    <?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" encoding="UTF-8"/>
    <xsl:template match="@* | node()">
      <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
    </xsl:template>
    <xsl:template match="Invoice" >
      <xsl:apply-templates/>
    </xsl:template>
    </xsl:stylesheet>
    Kind regards,
    Lode

  • Namespace Prefix in the Root Element of the variable

    Hi Gurus,
    We need to call a webservice which requires a namespace prefix at the root elemnt of the xml payload. But as we know that the default behaviour of BPEL removes the prefix so the invoke activity is failing and so we are stuck.
    I found this thread Namespace prefix in Root element missing during variable assignment but i feel the solution specified in this link works only in SOA 10g environment Please let us know what needs to be done?
    Appreciate a prompt response.
    NOTE: SOA Suite Version- 11.1.1.4
    Regards
    Ayush

    Hi All,
    we are also facing the same issue, Please provide the solution if anyone knows. We are also using the SOA Suite 11g Version.

  • Indesign CS3 XML Root element?? , Java Script

    Is there any way to tag the root element using javascript?
    The three usual ways without JS would be:
    Rename the tag in the tag pallete.
    Select and Retag the Element in the Structure.
    Or import an xml to replace the structure.
    This is the closest information I could find, thanks to Dave Saunders
    http://jsid.blogspot.com/2006/07/emaciated-anonymous-invisible-parent.html
    ~Mike

    Does this help:
    app.documents[0].xmlElements[0].markupTag.name = "Fred";
    Dave

  • Read XML root element tag in Java

    Is there any way I can read the tag of the root element? Based on the tag, I process the XML differently.
    Thank you.

    I think I figured it out. I can accomplish this by using the getTagName method. Sorry for the lack of detail in my original question.
    For those interested, I have a class that has XML passed to it. Depending on what the root tag name is, different activities needed to take place. I needed a way to read the tag in order to determine what actions needed to be performed.
    Thank you.

  • XML root elements

    Hi i am writing a sql select query to create an xml file.
    SELECT
    XMLELEMENT("data",
    XMLATTRIBUTES('http://smile.mit.edu/shelf/' as "wiki-url",
    'SIMILE JFK Timeline' as "wiki-section"),
    XMLELEMENT("event",
    XMLATTRIBUTES(e.IMP_DATE as "start",
    e.NAME||': '|| e.ECCTS as "title",
    e.IMP_DATE as "end")
    from monica_tab2 e;
    When this query runs, it appears to show the data tags as elements for every record. I want this to be a root element so that it only appear once for all the events.
    Is there any way i can do this? Examples will be appreciated
    Thanks
    Edited by: Monica B on Nov 10, 2008 7:21 AM

    Try using the XMLAGG function...
    SELECT
      XMLELEMENT("data",
                 XMLATTRIBUTES('http://smile.mit.edu/shelf/' as "wiki-url",
                               'SIMILE JFK Timeline' as "wiki-section"),
                 XMLAGG(XMLELEMENT("event",
                                   XMLATTRIBUTES(e.IMP_DATE as "start",
                                                 e.NAME||': '|| e.ECCTS as "title",
                                                 e.IMP_DATE as "end")
    from monica_tab2 e;

  • AS3 XML adds custom namespace declarations

    What I am doing is uncompressing .xlsx file and reading its contents. Then add some rows to sheets and then compress all the files in .xlsx format.
    The problem is with sharedStrings.xml (probably with other files too). Some xml tags look like this:
    <t xml:space="preserve">Banner Set 1</t>
    But when i convert the xml string to XML object (new XML(xml_string)), it gets ugly:
    <t aaa:space="preserve" xmlns:aaa="http://www.w3.org/XML/1998/namespace">Banner Set 1</t>
    Well, I understand why this happens. It is because the namespace xml isn't declared on that node, so AS3 takes it's default namespace and declares it there and renames it.
    This is the reason, why Excel refuses to read this file. I don't want XML object to mess with the namespaces and just leave them as they are. Is it possible to do this with the native XML library? Or maybe there are some other libraries that could help me in this case?

    be consistent in the definition of the NS.
    at the top of the XSL you write: xmlns:web="http://.../web"
    then in an element: xmlns:web="urn:jsptld:WEB-INF/tld/web.tld"
    if you are consistent, then it will be declared only on top of the resulting XML.

  • How to add dynamic jquery fields into DB

    I am using the script from: http://www.coldfusionjedi.com/index.cfm/2009/2/19/Using-jQuery-to-add-form-fields to dynamically add fields to a form.  I am having trouble actually inserting the fields into a DB.  It seems that the field name is the same each time so they just get combined into one variable.  For instance, if field 1 is "John" and they add another person and his name is "Frank" field1 becomes, "John, Frank".
    I have a few more fields then that, so I am unsure how to proceed.  Anyone have any ideas or code samples that have worked for them?  Essentially I am trying to loop through the form and insert each additional field seperately.
    Any ideas?
    Thanks a ton

    Thanks for the help!  I am still stuck as to exactly how this will be done. My form is as follows:
    Type:
    Price:
    Unite:
    Name:
    and users can add another product etc so there will be more fields for each additional product (which all seem to get truncated as a comma seperated list in the form value)
    Here is what I have so far, after the form is submitted:
    <cfloop item="key" collection="#form#">
    <cfquery name="insertnote">
    INSERT INTO Deals (type, price, unit, name) VALUES ('#form.type#', #form.price#, '#form.unit#', '#form.name#'  )
      </cfquery>
    </cfloop>
    I honestly don't use loops like this very often so I apologize for having a lack of understanding.  I know you mentioned making them nested loops but I dont' know how to do it and have it successfully insert the appropriate data.  Everytime I try it doesnt come out right.

  • How to add DTD syntax line into XML using java code

    Hi,
    I am building xml file with java, usiing document.createElement()
    and document.appendChild(element),
    like that
    now i need to add dtd file path and synatx in the top of the xml file,
    how can i do it through java code
    any body could help me
    i appreciate your help.
    thanks
    Durga

    Hi Suneetha,
    Thanks for your reply..
    Now i am getting docType in xml file but not in the format of what i want
    please look at my code
    i need
    <!DOCTYPE myRootElement SYSTEM "myXMLDTD.dtd" >
    but i am getting
    <!DOCTYPE myRootElement PUBLIC "" "myXMLDTD.dtd">
    There is change i need to get the SYSTEM in place of PUBLIC and i need to get rid of "" code between dtd and PUBLIC
    for this i am doing in my code as
    DocumentType theDocType = new DocumentImpl().createDocumentType ("SYSTEM","","myXMLDTD.dtd");
    Document theDoc = new DocumentImpl(theDocType);
    i dn't know what is the wrong ? i dn't know what are the parameters at what place to pass if you know any thing just let me know
    thanks in advance
    and i apperciate you help.
    Durga

  • Can I include a Dynamic HTML Table into XML Forms?

    Hi,
    I have a requirement For XML Forms that I don´t know if possible, the requirement is that I can let the user create a HTML Table in a template generated by XML Forms, so he can include in the Content a HTML Table that is displayed with the elements he decided.
    Thanx in Advanced!
    Gerardo J

    Hi,
    To Create HTML Tables in the XML Forms, use the HTML Editor from the Menu and Function bar. When the form is generated then tables can be created using this editor.
    Thanks and Regards,
    Gauri Gosavi.

  • How to add script editor webpart into xml format

    Hi,
    I need to add the script editor webpart on to my sharepoint page using this format :
    <AllUsersWebPart WebPartZoneID="WebPartZone6" WebPartOrder="1">
            <![CDATA[
          <webParts>
           <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
            <metaData>
               <type name="Microsoft.SharePoint.WebPartPages.ScriptEditorWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
               <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
            </metaData>
            <data>
             <properties>
              <property name="Title" type="string">$Resources:core,ScriptEditorWebPartTitle;</property>
              <property name="Description" type="string">$Resources:core,ScriptEditorWebPartDescription;</property>
              <property name="ChromeType" type="chrometype">None</property>
                  <property name="Content" type="string">
                       &lt;style type=&quot;text/css&quot;&gt;.header {;top: 100px;left: 10px;width: 100%;color:#ff8800!important;}.headerpara {;top: 140px;left:
    10px;width: 90%;color:white;}.image {;width: 100%;}.heading {;bottom: 10px;left: 20px;width: 85%;color: white!important;}&lt;/style&gt;
                  </property>
             </properties>
            </data>
           </webPart>
          </webParts>
            ]]>
    the webpart is successfully added to the page but when it renders it's css is not got applied on to the page instead the css gets render as a text which is :
    <style type="text/css">.header {;top: 100px;left: 10px;width: 100%;color:#ff8800!important;}.headerpara {;top: 140px;left: 10px;width: 90%;color:white;}.image {;width: 100%;}.heading {;bottom: 10px;left: 20px;width: 85%;color: white!important;}</style>
    i follwed the follwing link as an example :http://sharepointsnacks.blogspot.in/2014/02/sharepoint-2013-script-editor-web-part.html
    i am not sure is there anything which i am doing wrong but struggling a lot with this .
    Any help appreciated .
    Thanks

    Hi Avnish Gupta,
    Continue to Lakshmanan, you may need to add your CSS Styles in a <ContentLink> tag like below:
    <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
    </Content>
    More information:
    Adding content editor web part with default content through Visual Studio:
    http://spointdebo.blogspot.jp/2013/12/adding-content-editor-web-part-with.html
    Best regards
    Zhengyu Guo
    TechNet Community Support

  • Declaring namespaces ONLY on root element during serialization

    I'm using JAXP 1.3 and I'd like to be able to serialize a document so that the namespace declarations are only specified once on the root element and not repeated throughout the document.
    I'm working on a journal publication system and the request came from our users (i.e., editors) who say the repeated declarations are distracting when editing the XML. They are using an XML editor (Arbortext), but when they have the view set to display tags all the namespace declarations really clutters up the screen. In particular, we use the MathML namespace:
    <m:math overflow="scroll" xmlns:m="http://www.w3.org/1998/Math/MathML">
    Can this be done?
    Thanks,
    Jeff Bailey

    It's just declared on on the root element on the input file.
    I just tried what you suggested and it worked great. The mathml namespace is only declared on the root element in my output file now.
    Odd that there's a difference between the two methods. For posterity, here's the code I used to serialize the XML:
    TransformerFactory transformerFactory = TransformerFactory
    .newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.ENCODING, "US-ASCII");
    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
    doc.getDoctype().getPublicId());
    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
    doc.getDoctype().getSystemId());
    OutputStream outputStream = new FileOutputStream(new File(
    "C:\\temp\\foo.xml"));
    transformer.transform(new DOMSource(doc),
    new StreamResult(outputStream));
    Thanks very much for your help.
    Jeff

  • Adding namespace prefix to the XMLa root element

    I am facing a problem in our application. I am assigning an XML content to a XSD variable. While assignment operation is performed the prefix of the XML root element alone is getting replaced with default namespace, though the source XML has the prefix. Please let me know if any patch or workaround is available to address this issue.
    Thanks!

    Hi All,
    we are also facing the same issue, Please provide the solution if anyone knows. We are also using the SOA Suite 11g Version.

  • Create Root Element in XML

    Hi Experts,
    I am develpoing a program to generate xml file as output. I am using the method CL_IXML and other interfaces to generate the xml data. Here I need to create a root element. I did search in SDN but I couldnot found anything to generate xml root element.
    My output should be like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <Request Version="11.1" IssuerID="1">
            <CreatePurchaseRequest
                RequestID="123456"
                Commonname="test"
            </CreatePurchaseRequest>
    </Request>
    Can anybody plz suggest how can I generate the root element Request here?
    Regards,
    Ranganadh.

    Thanks Sandra,
    My issue got resolved.
    I just created the root element using the method create_sample_element and set the attributes using set_attributes method.
    Thanks for your help.
    w_ixml = cl_ixml=>create( ).
          w_document = w_ixml->create_document( ).
          w_root = w_ixml->create_document( ).
          IF w_document IS INITIAL.
            RAISE EXCEPTION TYPE cx_cmx_da_exception
              EXPORTING
                textid = cx_cmx_da_exception=>cx_cmx_da_error_internal.
          ENDIF.
          w_encoding = w_ixml->create_encoding(
                                 character_set = 'utf-8'
                                 byte_order    = if_ixml_encoding=>co_none ).
          w_document->set_encoding( w_encoding ).
          w_element_inv1  = w_document->create_simple_element(
                      name = 'OrbiscomRequest'
                      parent = w_document ).
          w_element_inv1->set_attribute( name = 'Version'
                                         namespace = ''
                                         value = '11.1' ).
          w_element_inv1->set_attribute( name = 'IssuerID'
                                         namespace = ''
                                         value = '1' ).

Maybe you are looking for