on 05-05-2008 11:03 AM
Hello,
I want to generate an XML file that starts with the following tags:
<?xml version="1.0" encoding="UTF-8"?>
<ps-persistence version="8.12.1">
<scenarioList>
But I can only generate the following:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_PS xmlns:ns1="http://cobega.es/Numetrix">
<scenarioList>
I have 2 problems:
1 - SAP XI doesn't allow me to create an element with a "-" in the tag name. How can I skip that verification? Or how can I create a tag with a "-"?
2 - SAP XI inserts the tag <ns1:................> with the message type namespace. But the program that have to read this XML file doesn't need that tag and it's a problem. How can I configure XI to not add this tag?
You can do with this by adding a Java class in the interface mapping.
Include the following tags as a header in Java Mapping.
<?xml version="1.0" encoding="UTF-8"?>
<ps-persistence version="8.12.1">
Parse the XML file from
<scenarioList> to </scenarioList> and add it to the above class in Java Mapping.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks sekhar,
I don't know how does it works. If I understand you, I have to go to Interface mapping and add a Java Class under the message mapping program? Is that ok?
And now, my question is, where and how can I create and develope that Java class? Sorry but I've never used that feature yet and I don't have knowledge of java (only ABAP)
I don't know how does it works. If I understand you, I have to go to Interface mapping and add a Java Class under the message mapping program? Is that ok?
Yes.
And now, my question is, where and how can I create and develope that Java class? Sorry but I've never used that feature yet and I don't have knowledge of java (only ABAP)
You can use Netweaver developer studio to implement this.
Hi Marshal,
You have to use Java Mapping To .you can use following sample code to implement your requirement
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class SimpleForwardMappingString extends DefaultHandler implements StreamTransformation
{
private static final String m_prologue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
private StringBuffer m_totalElementsBuffer = null;
public static void main(String args[])
{
try
{
InputStream in = new FileInputStream(new File("C:
input.xml"));
OutputStream out = new FileOutputStream(new File("C:
output_Out.xml"));
SimpleForwardMappingString myMapping = new SimpleForwardMappingString();
long startTime1 = System.currentTimeMillis();
/** Get the components of the Start time */
myMapping.execute(in, out);
long endTime1 = System.currentTimeMillis();
long totalMemory1 = Runtime.getRuntime().totalMemory();
long freeMemory1 = Runtime.getRuntime().freeMemory();
System.out.println ("The memory is "+(totalMemory1 - freeMemory1));
/** Get the components of the End time */
System.out.println("Time taken : " + (endTime1 - startTime1)+ " milli seconds");
myMapping = null;
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void getXMLDoc(InputStream inputStream,OutputStream outputStream)
{
long startTime1 = System.currentTimeMillis();
SAXParserFactory factory = SAXParserFactory.newInstance();
try
{
factory.setNamespaceAware(true);
factory.setValidating(false);
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(inputStream, this);
}
catch (FactoryConfigurationError e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void execute(InputStream arg0, OutputStream arg1)
throws StreamTransformationException
{
getXMLDoc(arg0,arg1);
try
{
arg1.write(m_totalElementsBuffer.toString().getBytes("UTF8"));
m_totalElementsBuffer = null;
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
public void setParameter(Map arg0)
{
}
public void startDocument()throws SAXException
{
m_totalElementsBuffer = new StringBuffer(50000);
/** Appending the Prologue and NameSpace to StringBuffer*/
m_totalElementsBuffer.append(m_prologue);
}
public void endDocument()throws SAXException
{
}
public void startElement(String namespaceURI, String name, String qName, Attributes attrs)
throws SAXException
{
if(name.equalsIgnoreCase("vchmsg03"))
{
m_totalElementsBuffer.append("<").append("ns0:vchmsg xmlns:ns0=\"http://surf.nl/vch/berichten\"" ).append(">");
}
else
m_totalElementsBuffer.append("<").append("ns0:"+name).append(">");
}
public void endElement(String uri, String name, String qName) throws SAXException
{
if(!name.equalsIgnoreCase("vchmsg03"))
{
m_totalElementsBuffer.append("</").append("ns0:" + name).append(">");
}
else
{
m_totalElementsBuffer.append("</").append("ns0:vchmsg").append(">");
}
}
public void characters(char buf[], int offset, int len)
throws SAXException
{
{
String s = new String(buf, offset, len);
if (null != s && s.length() >0)
m_totalElementsBuffer.append(s.trim());
}
}
}
Do thye Required Changes
Reward Points If helpful
Thanks
Sunil Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can also the XMLAnonymizerBean to get rid of namespaces ...
For "-" in tag names, I do not know why XI does not tolerate them (they are supported with some restrictions according to http://www.w3.org/TR/REC-xml/#sec-common-syn), but maybe it is possible to "bypass" this by editing the XSD and reloading it with the "-" in names. I dunno possible impacts on XI mechanisms
Rgds
Chris
Edited by: Christophe PFERTZEL on May 5, 2008 12:39 PM
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.