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
Similar Messages
-
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 -
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,
KennethHi 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
AyushHi 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
~MikeDoes 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. -
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 AMTry 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; -
How to add namespace prefix to XML file?
I have a file(XML) to proxy scenario. I 've created an asynch Inbound message and a asynch Outbound message.
I have generated the class in Sproxy of my R/3 System.
In the Integration directory I have 2 business system :
-one which sent the file
-my r/3 system
System which send file generate XML like this:
<?xml version="1.0" encoding="UTF-8" ?>
<batch id="20080211001" customer="some customer" user="user" language="EN">
<structure>
<localization>
<string id="customer" text="Customer" />
etc........
As you see, it have not any namespace prefix.
How can I insert namespace prefix in this file with XI tools?Hi Pavel
I am also facing the same issue
my XML structure is quite complex
<ROW EVENT="RE" SEQ="9" MORE="Y" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<FileDate Internal="61409" ROWID="Y">02/17/2009</FileDate>
<FileSeq ROWID="Y">9</FileSeq>
<Event>RE</Event>
<Grp>3</Grp>
<LinkFileTime>42324</LinkFileTime>
<Mrn></Mrn>
<ROW DESCR="RE" TABLE="PAT" EVENT="RE">
<BusTel/>
<BusTelHipaaConsent/>
<Cont1Addr1/>
<ROW DESCR="RE" TABLE="INS" EVENT="RE">
<DictRef1/>
<DictRef10/>
Do i have to create the Message Interface for Outbound Synchronous ..
<DictRef11/> -
Add xmlns tag to Xml file using DBMS_XMLGEN
I am using Oracle Release 10.1.0.4.2 version .
I want to create a xml file according to some data available in the relational database tables. For the same i created object types and then view with the object types since data is scattered in many tables.
Then i used DBMS_XMLGEN.getxml to generate the xml with query from the object view.
Is there an option to add xmlns attribute to the generated xml file.
Please let me know if any additional details are needed.If you want to add the namespace declaration in the root element, I don't think it's possible with DBMS_XMLGEN directly.
You can instruct DBMS_XMLGEN to treat some object fields as XML attributes by prefixing them with "@" (e.g. "@my_attribute") but you cannot control that for enclosing elements.
A possible solution is to add it afterwards using XSLT, or insertChildXML, but apparently the latter is not available in your version.
However...
For the same i created object types and then view with the object types since data is scattered in many tables.Since the data comes from different tables, why not use SQL and SQL/XML functions to build the document?
It's straightforward, simple, and doesn't need additional objects.
select xmlelement("Departments",
xmlattributes('http://xmlns.example.org' as "xmlns")
, xmlagg(
xmlelement("Department",
xmlattributes(d.deptno as "Id")
, xmlelement("Name", d.dname)
, xmlelement("Employees"
, xmlagg(
xmlelement("Employee",
xmlattributes(e.empno as "Id")
, xmlforest(
e.ename as "Name"
, e.job as "Job"
) order by e.empno
) order by d.deptno
from scott.dept d
join scott.emp e on e.deptno = d.deptno
group by d.deptno, d.dname
;Output :
<Departments xmlns="http://xmlns.example.org">
<Department Id="10">
<Name>ACCOUNTING</Name>
<Employees>
<Employee Id="7782">
<Name>CLARK</Name>
<Job>MANAGER</Job>
</Employee>
<Employee Id="7839">
<Name>KING</Name>
<Job>PRESIDENT</Job>
</Employee>
<Employee Id="7934">
<Name>MILLER</Name>
<Job>CLERK</Job>
</Employee>
</Employees>
</Department>
<Department Id="20">
<Name>RESEARCH</Name>
<Employees>
<Employee Id="7369">
<Name>SMITH</Name>
<Job>CLERK</Job>
</Employee>
<Employee Id="7566">
<Name>JONES</Name>
<Job>MANAGER</Job>
</Employee>
<Employee Id="7902">
<Name>FORD</Name>
<Job>ANALYST</Job>
</Employee>
</Employees>
</Department>
<Department Id="30">
<Name>SALES</Name>
<Employees>
<Employee Id="7499">
<Name>ALLEN</Name>
<Job>SALESMAN</Job>
</Employee>
<Employee Id="7521">
<Name>WARD</Name>
<Job>SALESMAN</Job>
</Employee>
<Employee Id="7654">
<Name>MARTIN</Name>
<Job>SALESMAN</Job>
</Employee>
<Employee Id="7698">
<Name>BLAKE</Name>
<Job>MANAGER</Job>
</Employee>
<Employee Id="7844">
<Name>TURNER</Name>
<Job>SALESMAN</Job>
</Employee>
<Employee Id="7900">
<Name>JAMES</Name>
<Job>CLERK</Job>
</Employee>
</Employees>
</Department>
</Departments> -
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 BaileyIt'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. -
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' ). -
Root element required error in syndication
Hi,
We have added few new fields into the main table. Now accordingly we need to update the Oubound map to include these new fields. I have created a new XSD file having these new fields. But when I try to use this in syndicator to update, it throws me an error back saying "Root element required". I checked in SDN but couldnt find enough clues.
Any pointers will be highly appreciated.
Regards,
Ponraj MHello,
There are few possible root causes to this error appearing in MDM Syndicator:
1. This error indicates that the XSD is not valid as there is no declaration of the root element.
If you try to validate this XSD in XMLspy you will receive a similar error.
2. The XSD declares the root element but it does not appear in the XML.
If you validate the XML against the XSD in XMLspy you will receive a similar error.
3. An illegal character in the XSD root element declaration makes it impossible for Syndicator to detect it.
Please check these possible causes.
Best regards,
Hedda Cohen. -
Name Space deplaration in root element in soap message
My soap client is having problems interpreting the response received from my Java service. When implemented using Endpoint.publish it works, whoever once packaged up inside an WAR file it break my client. After some investigation I found that the response message differs slightly. It seems that the namespace is declared on the root element using JAX-WS 2.0, and within the content body using JAX-WS 2.1. As I am not able to change the soap framework on my client, I am wondering if there is an option I could get either JAX-WS or JAX-B to produce the response message in the working format.
This is the fault generated by Endpoint.publish (Java5 with JAX-WS 2.0):
HTTP/1.1 500 Internal Server Error
Content-length: 507
Content-type: text/xml; charset=utf-8
<?xml version="1.0" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://addressbookserver.j2anywhere.com/">
<soapenv:Body>
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>soapenv:Server</faultcode>
<faultstring>Unable to verify license</faultstring>
<detail><ns1:LicenseException>
Unable to verify license
</ns1:LicenseException></detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>This is the fault received from Tomcat (Java5 with JAX-WS 2.1):
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Date: Thu, 19 Jun 2008 22:26:17 GMT
Connection: close
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>Unable to verify license</faultstring>
<detail>
<ns2:LicenseException xmlns:ns2="http://addressbookserver.j2anywhere.com/">
Unable to verify license
</ns2:LicenseException>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>Thanks in advanceThose two documents look functionally the same to me. It shouldn't matter whether the namespaces are declared at a higher level than necessary. If you have a client that treats those two documents differently then I would say it's not working correctly.
-
Unnecessary Namespace declarations
Hi,
When mapping (graphic) to an externally defined XML schema where some elements belong to different namespaces I get namespace declarations on each element in the resulting XML instance even though they refer to the same ns name. The problem is that the XML document, even though valid, is very verbose. Is there a way to get all ns declarations in the root element instead without using XSLT?
Example output
<?xml version="1.0" encoding="utf-8" ?>
<ns1:RootElement xmlns:ns1="http://foo.com">
<ns2:Element1 xmlns:ns2="http://junk.com" />
<ns2:Element2 xmlns:ns2="http://junk.com" />
<ns2:Element3 xmlns:ns2="http://junk.com" />
</ns1:RootElement>
I would like to get something like this instead:
<?xml version="1.0" encoding="utf-8" ?>
<ns1:RootElement xmlns:ns1="http://foo.com" xmlns:ns2="http://junk.com">
<ns2:Element1 />
<ns2:Element2 />
<ns2:Element3 />
</ns1:RootElement>
Kind regards JohanHi,
I was probably not clear enough in my question.
My Scenario is CRM -> Xi -> External system.
The inbound interface to the external system is a predefined XML Schema where not all components/elements belong to the same namespace.
When executing a mapping, created with the graphical mapping tool in Xi, the resulting XML document/Instance is valid but very verbose since XI put namespace declarations in every element over and over again instead of just putting them once in the root element.
I don't think this has anything to do with the XSD, but rather with the mapping program.
The result is that the receiving system takes a performance hit. I would like to find a way to force XI to just declare the same ns once in the root element instead of over and over again?
kind regards Johan
Maybe you are looking for
-
Loading an "MXML Component" at run-time creates a null object.
Hello! I have a simple Flex 3 project with an MXML application file (the parent) and an MXML component file (the child). At run-time I create childs of this component, and I add it to the stage using a simple "this.addChild()" call. Now, besides that
-
I've tried connecting my 2011 Macair to my LED tv via mini DP to HDMI port. The video works fine but there is no sound. I tried opening network preferences and went to the sound section but it does not show my TV to be selected as an output option. P
-
Hey i just brought an ipod 8gb nano and it wont connect to the computer but it will charge on it how do i make it read the computer??
-
Hello All, I frequently use my mac in an office that many of my co-workers have access to. I'd like to know of a quick way to lock my screen without putting it in sleep mode or using the screen saver/expose feature. I have the Lock Screen icon in my
-
How to create button in selection screen
hi experts can u help me plzzzzzzzzzzz for this